我有一个非常奇怪的问题。在VS2010服务器资源管理器中,我可以连接到SQL Server并执行存储过程。然而,当我尝试这样做的代码我得到一个异常抛出:Visual Studio服务器资源管理器连接到数据库,但在代码中抛出异常
xp_cmdshell的代理帐户信息无法检索或 无效。验证“## xp_cmdshell_proxy_account ##”凭证 存在并且包含有效信息。
现在,也许我在代码中使用了错误的凭据,但后来我从服务器资源管理器复制了连接字符串,并将其放入我的配置文件中的连接字符串中。不过,同样的错误。
这里是做存储过程的连接和调用代码:
public static DataSet callStoredProcedure(string procedure, params SqlParameter[] args)
{
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet dataSet = new DataSet();
string connString = ConfigurationManager.ConnectionStrings["App"].ConnectionString;
try
{
using (SqlConnection conn = new SqlConnection(connString))
using (SqlCommand command = conn.CreateCommand())
{
conn.Open();
if (args != null)
{
foreach (SqlParameter param in args) command.Parameters.Add(param);
}
command.CommandText = procedure;
command.CommandType = CommandType.StoredProcedure;
adapter.SelectCommand = command;
adapter.Fill(dataSet, "tabela");
}
}
catch (SqlException exception)
{
throw new Exception("SqlClient exception", exception);
}
return dataSet;
}
这里是连接字符串,它是从服务器资源管理器使用连接字符串复制相关的XML配置:
<connectionStrings>
<add name="App" connectionString="Data Source=db2.myapp.com,49178\hosting;Initial Catalog=app;User ID=appuser;Password=f00barbaz" providerName="System.Data.SqlClient" />
</connectionStrings>
此外,服务器资源管理器可以连接到服务器并执行存储过程,但我的代码不断抛出相同的异常。什么可能导致这个?
谢谢
编辑
要清楚:服务器资源管理器可以都连接,并与我的代码使用相同的连接字符串执行存储过程。然而我的代码抛出一个异常。
'\ hosting'是一个命名实例。如果SQL Server浏览器正在运行,则不需要端口规范;我一直能够连接到命名实例而不指定端口。 – 2012-02-25 20:27:12