C# 调用链接服务器过程
如果在链接服务器上调用过程,则会出现以下错误: 消息0,级别20,状态0,第0行 当前命令发生严重错误。如果有结果,则应放弃 它适用于SSMS,也适用于经典asp,但不适用于这里。我发现了一些类似的问题,但没有答案。我不会(不能)直接连接到链接的服务器并在本地执行该过程。它必须作为:myLinkedServer.Database.dbo.myProcedure执行 有什么想法吗C# 调用链接服务器过程,c#,sqlcommand,C#,Sqlcommand,如果在链接服务器上调用过程,则会出现以下错误: 消息0,级别20,状态0,第0行 当前命令发生严重错误。如果有结果,则应放弃 它适用于SSMS,也适用于经典asp,但不适用于这里。我发现了一些类似的问题,但没有答案。我不会(不能)直接连接到链接的服务器并在本地执行该过程。它必须作为:myLinkedServer.Database.dbo.myProcedure执行 有什么想法吗 using (SqlCommand getOutput = new SqlCommand()) {
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();
我找到了一个解决方案:
getOutput.CommandText = "EXEC myLinkedServer.Database.dbo.myProcedure";
getOutput.CommandType = CommandType.Text;
在链接服务器上调用过程时,命令类型应为文本 如果此答案是解决方案,请将其标记为解决方案。