私は非常に特殊な問題があります。 VS2010 Server Explorerでは、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>
ここでも、サーバーエクスプローラは、サーバーに接続し、ストアドプロシージャを実行しますが、私のコードは常に同じ例外をスローすることができます。これを引き起こす原因は何ですか?
はあなたにそれを明確にする
EDIT
ありがとう:サーバーエクスプローラをの両方を接続して、自分のコードが使用するのと同じ接続文字列でストアドプロシージャを実行することができます。しかし、私のコードは例外をスローします。
'\ hosting'は名前付きインスタンスです。SQL Serverブラウザが実行されている場合、ポートの指定は必要ありません。私はいつもポートを指定せずに名前付きインスタンスに接続することができました。 –