NigelRocks
asked on
Connecting to SQL Server from VB6
Hello,
I'm trying to connect to a SQL Server (2005) database from Visual Basic 6.0. The attached code produces no errors, yet never fills the dataset.
Thanks in advance for your help.
I'm trying to connect to a SQL Server (2005) database from Visual Basic 6.0. The attached code produces no errors, yet never fills the dataset.
Thanks in advance for your help.
Dim thisWorkspace As DAO.Workspace
Set thisWorkspace = CreateWorkspace("", "admin", "", dbUseODBC)
Dim thisConnection As DAO.Connection
Set thisConnection = thisWorkspace.OpenConnection("", , , "ODBC;DATABASE=KnowledgeTracker;DSN=KTracker")
Set gdbKnowledgeTracker = thisConnection.Database
Dim rs As DAO.Recordset
Dim sSQL As String
sSQL = "SELECT * FROM Problems"
Set rs = gdbKnowledgeTracker.OpenRecordset(sSQL)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>My compiler choked on this: ... Set thisConnection = New Adodb.Connection
That's because DAO does not have a Connection object, only a Database object. ADO (ADODB) has a connection object.
The code 3_S posted for you using ADO only should work for you.
That's because DAO does not have a Connection object, only a Database object. ADO (ADODB) has a connection object.
The code 3_S posted for you using ADO only should work for you.
ASKER
I added the Microsoft ActiveX Data Objects 2.8 Library reference.
I got a "variable not defined" error on this line;
thisconnecton.Open = "Provider=sqloledb;Network Library=DNETLIB;datasource =SQLSERVER ,1433;Init ial catalog=KnowledgeTracker;T rusted Connection=Yes;Encrypt=YES "
These two lines above it define the object:
Dim thisConnection As ADODB.Connection
Set thisConnection = New ADODB.Connection
If this code has worked for you, there must be something VERY different about our IDEs.
I got a "variable not defined" error on this line;
thisconnecton.Open = "Provider=sqloledb;Network
These two lines above it define the object:
Dim thisConnection As ADODB.Connection
Set thisConnection = New ADODB.Connection
If this code has worked for you, there must be something VERY different about our IDEs.
Did you copy paste the line with the 'variable not defined' error
thisconnecton is not the variable you defined: thisConnection is (letter i is missing in you posted code)
You can check this by typing thisconnection and then the point. If no propositions are made then you typed your variable wrong.
I would also recommend that you always add option explicit to every form/module/class you add in a project. With this option you must declare every variable else you get compiler error to warn you.
I use VB6 with sp5
thisconnecton is not the variable you defined: thisConnection is (letter i is missing in you posted code)
You can check this by typing thisconnection and then the point. If no propositions are made then you typed your variable wrong.
I would also recommend that you always add option explicit to every form/module/class you add in a project. With this option you must declare every variable else you get compiler error to warn you.
I use VB6 with sp5
Sorry. The i was a typo of mine in thisConnection
ASKER
Yes, it was a typo.
I also got an error on:
thisConnection.Open = " "
It has to be
thisConnection.Open(" ")
I'll get back to you about what happens.
I also got an error on:
thisConnection.Open = " "
It has to be
thisConnection.Open(" ")
I'll get back to you about what happens.
{very wild guess}
Lose the = sign
thisconnecton.open "Provider=sqloledb;Network Library=DNETLIB;datasource =SQLSERVER ,1433;Init ial catalog=KnowledgeTracker;T rusted Connection=Yes;Encrypt=YES "
Lose the = sign
thisconnecton.open "Provider=sqloledb;Network
ASKER
It doesn't like this line:
thisConnection.Open ("Provider=sqloledb;Networ k Library=DNETLIB;datasource =SQLSERVER ,1433;Init ial catalog=KnowledgeTracker;T rusted Connection=Yes;Encrypt=YES ")
Where in the above string would I tell it what server to use?
thisConnection.Open ("Provider=sqloledb;Networ
Where in the above string would I tell it what server to use?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is the string that did it:
thisConnection.Open "Driver={SQL Server};Server=COPS14\COPS DEV;Databa se=Knowled geTracker; Trusted_Co nnection=Y es;"
thisConnection.Open "Driver={SQL Server};Server=COPS14\COPS
ASKER
Dim thisConnection As Connection
Set thisConnection = New Adodb.Connection