Hi
I am trying to execute a sql sp in ms excel. it seems like i am doing something wrong that i couldnt figure out.
here is the code
========
Sub PutRecordsetInRange()
Dim cn As ADODB.Connection
Dim cd As ADODB.Command
Dim rsData As ADODB.Recordset
Set cn = New ADODB.Connection
With cn
.CursorLocation = adUseClient
.ConnectionString = "DRIVER=SQL Server;SERVER=ServerName; UID=;PWD=;DATABASE=Northwind"
.Mode = adModeRead
.ConnectionString = "ODBC;DRIVER=SQL Server;SERVER=END4258-5;UID=;APP=Microsoft Office 2003;WSID=END4258-5;DATABASE=Northwind;Trusted_Connection=Yes"
.Open
End With
Set cd = New ADODB.Command
With cd
Set .ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "SalesByCategory"
.CommandTimeout = 180
Set rsData = .Execute
End With
With rsData
If .State = adStateOpen Then
If Not (.BOF And .EOF) Then
Range("A1").CopyFromRecordset rsData
End If
.Close
Else
'/ error msg will be there
End If
End With
Set rsData = Nothing
Set cd = Nothing
cn.Close
Set cn = Nothing
End Sub
when i run this code, i get an error message which is not helpfull at all. Here is the error msg
===
Microsoft Visual Basic
Runtime error '-2147467259(80004005)'
Automation Error
Unspecified Error
=====
Thanks in advance
I am trying to execute a sql sp in ms excel. it seems like i am doing something wrong that i couldnt figure out.
here is the code
========
Sub PutRecordsetInRange()
Dim cn As ADODB.Connection
Dim cd As ADODB.Command
Dim rsData As ADODB.Recordset
Set cn = New ADODB.Connection
With cn
.CursorLocation = adUseClient
.ConnectionString = "DRIVER=SQL Server;SERVER=ServerName; UID=;PWD=;DATABASE=Northwind"
.Mode = adModeRead
.ConnectionString = "ODBC;DRIVER=SQL Server;SERVER=END4258-5;UID=;APP=Microsoft Office 2003;WSID=END4258-5;DATABASE=Northwind;Trusted_Connection=Yes"
.Open
End With
Set cd = New ADODB.Command
With cd
Set .ActiveConnection = cn
.CommandType = adCmdStoredProc
.CommandText = "SalesByCategory"
.CommandTimeout = 180
Set rsData = .Execute
End With
With rsData
If .State = adStateOpen Then
If Not (.BOF And .EOF) Then
Range("A1").CopyFromRecordset rsData
End If
.Close
Else
'/ error msg will be there
End If
End With
Set rsData = Nothing
Set cd = Nothing
cn.Close
Set cn = Nothing
End Sub
when i run this code, i get an error message which is not helpfull at all. Here is the error msg
===
Microsoft Visual Basic
Runtime error '-2147467259(80004005)'
Automation Error
Unspecified Error
=====
Thanks in advance