环境:
win2k server+vc6.0+Sql Server2000企业版现因在vc的程序中需要对远程数据库进行操作我的方案:
调用本地的存储过程"aaa"异地数据库的操作~!我采用的是链接服务器的方法,我用查询分析器执行存储过程"aaa"一切正常,也能对远程数据库进行操作。好了,问题来了。当我在vc的程序中调用dbcmd()函数来执行存储过程"aaa",程序就报错:"SQL Server常规错误,请检查来自SQL Ser的消息"
但是当我用dbcmd()对本地操作的存储过程时,一些正常,而且也能正确操作~!这是什么原因,那为大哥告诉我~!!

解决方案 »

  1.   

    在 DB-library 中執行存儲過程不是用 dbcmd()而是用 dbrpcinit() 吧!dbrpcinit
    Initializes a stored procedure or a remote stored procedure.Syntax
    RETCODE dbrpcinit ( 
    PDBPROCESS dbproc, 
    LPCSTR rpcname, 
    DBSMALLINT options );Arguments
    dbproc 
    Is the DBPROCESS structure that is the handle for a particular workstation/ Microsoft® SQL Server™ process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server. 
    rpcname 
    Is a pointer to the name of the stored procedure to be invoked. 
    options 
    Is a 2-byte bitmask of options for stored procedures. Specify 0 to indicate no options. The following options are available. 
     Option Description 
    DBRPCRECOMPILE Recompiles a stored procedure before it is executed. 
    DBRPCRESET Cancels a single stored procedure or a batch of stored procedures. If rpcname is specified, that new stored procedure is initialized after the cancellation is complete. 
    Returns
    SUCCEED or FAIL.
      

  2.   

    To execute a single stored procedure or a batch of stored procedures using DB-Library functions Call dbrpcinit once to initialize a new stored procedure. 
    Call dbrpcparam for each parameter of the stored procedure that does not have a default value. 
    Repeat steps 1 and 2 for each stored procedure in the batch. 
    Call dbrpcsend or dbrpcexec to send the entire stored procedure batch to SQL Server. 
    Call dbsqlok to wait for SQL Server to start returning results. 
    Call dbresults to process the results from each stored procedure. 
    If dbresults returns SUCCEED, call dbnextrow until it returns NO_MORE_ROWS to process the normal results from the stored procedure. If dbresults returns NO_MORE_RPC_RESULTS, and you want to retrieve status number and return-parameter information returned by the stored procedure, follow the steps given later. Repeat Step 6 until dbresults returns NO_MORE_RESULTS. 
    If you want to retrieve status number and return-parameter information returned by the last stored procedure in the batch, follow the steps given later.
      

  3.   

    用dbcmd()把要执行的命令放到命令缓冲区,然后调用dbsqlexec()来执行命令。