1

尝试从ax创建存储过程,今天陷入了麻烦。从x ++创建存储过程

下面是一个简单的例子:

static void testProcedureCreation(Args _args) 
{ 
    MyParamsTable myParams; 
    SqlStatementExecutePermission perm; 

    str sqlStatement; 

    LogInProperty Lp = new LogInProperty(); 
    OdbcConnection myConnection; 
    Statement myStatement; 
    ResultSet myResult; 
    str temp; 
    ; 

    select myParams; 


    LP.setServer(myParams.Server); 
    LP.setDatabase(myParams.Database); 
    //Lp.setUsername("sa"); 
    //Lp.setPassword("sa"); 

     sqlStatement = @"create procedure testproc 
       as begin 

       print 'a' 

       end"; 
    //sqlStatement = strFmt(sqlStatement, myStr); 
    info(sqlStatement); 
    perm = new SqlStatementExecutePermission(sqlStatement); 

    perm.assert(); 

    try 
    { 
     myConnection = new OdbcConnection(LP); 
    } 
    catch 
    { 
     info("Check username/password."); 
     return; 
    } 



    myStatement = myConnection.createStatement(); 
    myResult = myStatement.executeQuery(sqlStatement); 

    while (myResult.next()) 
    { 
     temp = myResult.getString(1); 
     info(temp); 

     if (strScan(temp, 'Error', 1, strLen(temp)) > 0) 
      throw error(temp); 
    } 

    myStatement.close(); 

    CodeAccessPermission::revertAssert(); 
} 

说实话,在我的真实的例子,我使用BCP和有很多的一些字符串连接| '和“”。

无论如何,这里是我得到:

enter image description here

对于一两个小时我不停的变换和重试了很多东西,并且一个好想法进入了我的脑海里。

“让我们尝试一个更简单的示例并检查结果!”

好的,没有运气,结果是一样的,你可以在上面的图片看到。

但没有任何理由,我想:在我SSMS实例,让我吃惊的

exec testproc 

,它的工作。我的小程序就在那里。

如果有人能解释这种行为,也许应该是正确的方法,这将是如此的美好。

+0

这是否帮助:http://stackoverflow.com/questions/12184152/how-to-get-the-results-of-a-direct-sql-call-to- a-stored-procedure('executeQuery' vs'executeUpdate')。不是在开发箱,所以不能真正深入了解这个问题。 –

+0

非常感谢Alex,executeUpdate做得非常好,我明白了原因。你可以请转发你的评论作为答案,所以我可以接受它吗?非常感谢Jan B. Kjeldsen。我确实迷失在此:) –

+0

很高兴我能帮上忙,作为答案。 –

回答