there are many ways.. You can use a Provider, or an ODBC driver:
with an ADODB control:
Load an ADODB control from the component window, and set its connection string using the sql driver.
Crearing a connection:
or go to Control Panel, ODBC drivers and create a new driver for Your SQL database, You can refer in Your application to it by its name.
for example:
Code:
Dim conn as new adodb.connection
conn.open "ODBCNAME"
** You can combine both methods above.. all the connection string will work for both.
Dim SQLCON As ADODB.Connection
Dim SQLRS As ADODB.Recordset
' Set the ADO SQLCON properties.
Set SQLCON = New ADODB.Connection
Set SQLRS = New ADODB.Recordset
With SQLCON
.ConnectionTimeout = 25 ' Time out for the SQLCON
.Provider = "sqloledb" ' OLEDB Provider
.Properties("Network Address".Value = "999.999.999.999" ' Set the ip address of your sql server
.CommandTimeout = 180 ' Set timeout for 3 minutes
.Properties("Network Library".Value = "dbmssocn" ' Set the network library to use win32 winsock tcp/ip
.CursorLocation = adUseServer ' For ADO cursor location
.Properties("User ID".Value = "xx" ' Set the user id
.Properties("Password".Value = "xxxxxxxxxxxxxx" ' Set the password
.Properties("Data Source".Value = "999.999.999.999" ' Set the ip address as the datasource
.Properties("Initial Catalog".Value = "xxxxxxxx" ' Set the database name
.Open
End With
With SQLRS
.Open "SELECT * FROM TABLENAME;", SQLCON, adOpenStatic, adLockReadOnly, adCmdText
End With
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.