2013-02-05 52 views
0

如果我呼籲鏈接服務器上的程序,我得到以下錯誤:呼叫鏈接的服務器程序

消息0,級別20,狀態0,0行 當前命令發生了嚴重錯誤。如果有的話,結果應該被丟棄。

它適用於SSMS,它也適用於經典的asp,但不在這裏。我發現了一些類似的問題,但沒有回答。我不會(不能)直接連接到鏈接的服務器並在本地執行過程。它必須執行如下:myLinkedServer.Database.dbo.myProcedure

任何想法?

using (SqlCommand getOutput = new SqlCommand()) 
     { 

      getOutput.CommandText = "myLinkedServer.Database.dbo.myProcedure"; 
      getOutput.CommandType = CommandType.StoredProcedure; 
      getOutput.CommandTimeout = 300; 
      getOutput.Connection = conn; 

      conn.Open(); 
      using (SqlDataAdapter da = new SqlDataAdapter(getOutput)) 
      { 
       da.AcceptChangesDuringFill = false; 
       da.Fill(exportData);//here error happened 
       conn.Close(); 
       da.Dispose(); 

回答

0

我已經找到了解決辦法:

getOutput.CommandText = "EXEC myLinkedServer.Database.dbo.myProcedure"; 
getOutput.CommandType = CommandType.Text; 

當調用鏈接服務器上的程序,指令類型應爲文本。

+0

如果此答案是解決方案,請將其標記爲解決方案。 – VansFannel