Excel VBA executing SQL Server stored procedure - result set throwing error 3704 -
i trying execute sql server stored procedure excel vba. procedure returns rows result set object. however, while running code, throws error:
3704 operation not allowed when object closed
note:
there no problem database connection because select
query running on same connection object working fine.
here code:
dim cn adodb.connection dim rs adodb.recordset dim cmd adodb.command dim prm adodb.parameter dim rst new adodb.recordset set cn = new adodb.connection set cmd = new adodb.command thisworkbook.initialize cn.provider = "sqloledb" cn.properties("data source").value = thisworkbook.server cn.properties("initial catalog").value = thisworkbook.db cn.properties("user id").value = "xxxxx" cn.properties("password").value = "xxxxx" cn.open set cmd = new adodb.command cmd.commandtext = "generate_kpi_process_quality_check_runtime" cmd.commandtype = adcmdstoredproc cmd.activeconnection = cn set prm = cmd.createparameter("@currentmonth", adchar, adparaminput, 255, cmb_month.value) cmd.parameters.append prm set prm = cmd.createparameter("@center", adchar, adparaminput, 255, cmb_center.value) cmd.parameters.append prm rst.cursortype = adopenstatic rst.cursorlocation = aduseclient rst.cursorlocation = aduseserver rst.locktype = adlockoptimistic rst.open cmd if (rst.bof , rst.eof) 'some code end if
put
set nocount on
in stored procedure -- prevent output text generation "1 record(s) updated".
Comments
Post a Comment