Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Executing Stored Procedure

Hello,

I keep recievng the following message when trying to execute a sql server
stored procedure. My stored procedure displays results from a temp table and
works fine when I run it from sql server, but I receive the following message
when trying to execute if from excel:
"Operation is not allowed when object is closed"

Here is my code. can anyone provide some advice.

Sub newtest()

Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
Dim strConn As String

strConn = "PROVIDER=SQLOLEDB.1; Data Source=SJ-ISBI01D; Initial
Catalog=BI_DW; INTEGRATED SECURITY=sspi;"

cnPubs.Open strConn
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = strConn
cmd.CommandText = "BI_RR_TopOpp_Region"

Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset

rsPubs.ActiveConnection = cnPubs
Set rsPubs = cmd.Execute(, , adCmdStoredProc)
Sheet1.Range("A1").CopyFromRecordset rsPubs

rsPubs.Close
cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Executing Stored Procedure

Jenise,
I seem to remember that adCmdStoredProc does not work (with MySQL anyway),
but adCmdText does, even for stored procedures.

Also, not sure you need the line:
rsPubs.ActiveConnection = cnPubs

NickHK

"Jenise" wrote in message
...
Hello,

I keep recievng the following message when trying to execute a sql server
stored procedure. My stored procedure displays results from a temp table

and
works fine when I run it from sql server, but I receive the following

message
when trying to execute if from excel:
"Operation is not allowed when object is closed"

Here is my code. can anyone provide some advice.

Sub newtest()

Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
Dim strConn As String

strConn = "PROVIDER=SQLOLEDB.1; Data Source=SJ-ISBI01D; Initial
Catalog=BI_DW; INTEGRATED SECURITY=sspi;"

cnPubs.Open strConn
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = strConn
cmd.CommandText = "BI_RR_TopOpp_Region"

Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset

rsPubs.ActiveConnection = cnPubs
Set rsPubs = cmd.Execute(, , adCmdStoredProc)
Sheet1.Range("A1").CopyFromRecordset rsPubs

rsPubs.Close
cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing queries stored in database in Excel John B Excel Discussion (Misc queries) 0 December 15th 05 09:08 AM
Excel 2002 recalculation while executing VBA Procedure Ed Leshik[_2_] Excel Programming 1 March 25th 05 11:34 AM
Executing sub procedure when Excel starts strataguru[_18_] Excel Programming 2 September 23rd 04 11:27 PM
execute stored procedure Mark Goldin Excel Programming 3 April 7th 04 03:03 PM
Run a stored procedure in Excel 2K ArthurB Excel Programming 0 February 26th 04 04:46 PM


All times are GMT +1. The time now is 03:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"