jjc99
10-19-2011, 09:06 AM
Hi all
I am attempting to connect to an SQL Server database via VBA. I am using ADO.
My code is as follows
Private Sub Connect_to_SQLServer()
Dim oCon As ADODB.Connection
Dim oRS As ADODB.Recordset
Set oCon = New ADODB.Connection
oCon.ConnectionString = "Data Source=PC-001\SQLEXPRESS;Initial Catalog=MYDBNAME;Integrated Security=True"
oCon.Open
Set oRS = New ADODB.Recordset
oRS.ActiveConnection = oCon
oRS.Source = "Select * From tbl_News"
oRS.Open
oRS.Close
oCon.Close
If Not oRS Is Nothing Then Set oRS = Nothing
If Not oCon Is Nothing Then Set oCon = Nothing
End Sub
However, when I run this code I get the following error:
Run-time error '-2147217887 (80040e21)':
Multiple-step OLE DB operation generated errors. Check each OLE db status value, if available. No work was done.
Does anyone know how to go about solving this issue.
Any help would be greatly appreciated.
I am attempting to connect to an SQL Server database via VBA. I am using ADO.
My code is as follows
Private Sub Connect_to_SQLServer()
Dim oCon As ADODB.Connection
Dim oRS As ADODB.Recordset
Set oCon = New ADODB.Connection
oCon.ConnectionString = "Data Source=PC-001\SQLEXPRESS;Initial Catalog=MYDBNAME;Integrated Security=True"
oCon.Open
Set oRS = New ADODB.Recordset
oRS.ActiveConnection = oCon
oRS.Source = "Select * From tbl_News"
oRS.Open
oRS.Close
oCon.Close
If Not oRS Is Nothing Then Set oRS = Nothing
If Not oCon Is Nothing Then Set oCon = Nothing
End Sub
However, when I run this code I get the following error:
Run-time error '-2147217887 (80040e21)':
Multiple-step OLE DB operation generated errors. Check each OLE db status value, if available. No work was done.
Does anyone know how to go about solving this issue.
Any help would be greatly appreciated.