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

很高興我能幫上忙,作爲答案。 –

回答