hi i have great confusion to connecting vb with sqlserver. anybody can help me?.
How can I connect to SQL Server in VB6
Page 1 of 12 Replies - 6591 Views - Last Post: 15 October 2007 - 04:57 PM
Replies To: How can I connect to SQL Server in VB6
#2
Re: How can I connect to SQL Server in VB6
Posted 15 October 2007 - 12:43 AM
you can make connection with the followin code
*Always use code blocks when posting code
Public con As New Connection
Dim UserName As String
Dim Password As String
Dim ServerName As String
Dim DBName As String
UserName = ""
Password = ""
ServerName = ""
DBName = "databasename"
con.ConnectionTimeout = 5 ' Set the time out.
con.Provider = "sqloledb" ' Specify the OLE DB provider.
con.Properties("Data Source").Value = ServerName ' Set SQLOLEDB connection properties.
con.Properties("Initial Catalog").Value = DBName ' Set SQLOLEDB connection properties.
con.Properties("Integrated Security").Value = "SSPI" ' Set SQLOLEDB connection properties.
con.Open
*Always use code blocks when posting code
This post has been edited by muddasir: 15 October 2007 - 03:37 AM
#3
Re: How can I connect to SQL Server in VB6
Posted 15 October 2007 - 04:57 PM
There are 2 kinds of Connection Strings:
- To Local Server (local means to your machine).
--> Available authentification:
-----> Windows Authentification, Sql Server Authentification.
- To External Server (another machine in a network(local, internet, etc))
--> Available Authentification:
-----> Windows Authentification, Sql Server Authentification.
Available Authentification = The permition to conect to the sql server.
Lets see a Conection to a local server with SqlServer Authentification:
Lets explain the code, remember end a stament with ';':
-Driver ={SQL Server}; <-- driver to conect example SQLServer 7, 2000, 2005, etc.
-server=(local); conect to a local server.
-uid=sa; name of the user who wants a connection (example 'sa'). This a Sql Server Authentification becouse we are using an SQL Server to create a connection.
-pwd=; By default the user 'sa' has no password, if 'sa' got a password use it there.
-database=master; the database to conect.
Lets see a Conection to a local server with Windows Authentification:
PD: Remember you cant connect to a SqlServer in another machine with a Windows Authentification (well you can but its really complicated
.)
Lets explain the code, remember end a stament with ';':
-PROVIDER=sqloledb; <-- driver to conect example SQLServer 7, 2000, 2005, etc.
-Integrated Security=SSPI; user pc (local pc) who wants a connection .
-Initial Catalog=master; the database to conect.
-Data Source=(local); SqlServer Data source of the databases.
There are many properties, but this are the most import, remember always close your conecctions
...
Easy right???
- To Local Server (local means to your machine).
--> Available authentification:
-----> Windows Authentification, Sql Server Authentification.
- To External Server (another machine in a network(local, internet, etc))
--> Available Authentification:
-----> Windows Authentification, Sql Server Authentification.
Available Authentification = The permition to conect to the sql server.
Lets see a Conection to a local server with SqlServer Authentification:
'NEW CONEXTION OBJECT ------------------
Dim cnnConextion As New ADODB.Connection
'OPEN THE CONEXTION TO LOCAL SERVER
cnnConextion.Open "driver={SQL Server};" & _
"server=(local);uid=sa;pwd=''; database=master"
Lets explain the code, remember end a stament with ';':
-Driver ={SQL Server}; <-- driver to conect example SQLServer 7, 2000, 2005, etc.
-server=(local); conect to a local server.
-uid=sa; name of the user who wants a connection (example 'sa'). This a Sql Server Authentification becouse we are using an SQL Server to create a connection.
-pwd=; By default the user 'sa' has no password, if 'sa' got a password use it there.
-database=master; the database to conect.
Lets see a Conection to a local server with Windows Authentification:
PD: Remember you cant connect to a SqlServer in another machine with a Windows Authentification (well you can but its really complicated
'NEW CONEXTION OBJECT ------------------ Dim cnnConextion As New ADODB.Connection 'OPEN THE CONEXTION TO LOCAL SERVER cnnConextion.Open "PROVIDER=sqloledb; " & _ "Integrated Security=SSPI; " & _ "Initial Catalog=master; Data Source=(local);"
Lets explain the code, remember end a stament with ';':
-PROVIDER=sqloledb; <-- driver to conect example SQLServer 7, 2000, 2005, etc.
-Integrated Security=SSPI; user pc (local pc) who wants a connection .
-Initial Catalog=master; the database to conect.
-Data Source=(local); SqlServer Data source of the databases.
There are many properties, but this are the most import, remember always close your conecctions
Easy right???
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|