1

1 ソリューション。

2つのプロジェクト(1.WEB - 2.三層構造)

ストアド プロシージャの呼び出し: Web -> BOL -> BLL -> DAL。

DAL のメソッド: 接続文字列を取得して実行します。

 public DataSet ExecuteSQL(string sp, Persona user)
    {
        EH eh = new EH(); // Error_Handling.cs object
        try
        {
            DataSet ds = new DataSet();
            string connectionString = null;
            connectionString = GetNewConnection("BO"); //HERE COMES THE ERROR
            SqlConnection conn = new SqlConnection(connectionString);
            using (conn)
            { ....

GetNewConnection()。

 public string GetNewConnection(string server)
    {
        return ConfigurationManager.ConnectionStrings["BO"].ConnectionString;
    }

目的の接続を指定するApp.Configフラグメント

<connectionStrings>
<add name="BO"
    connectionString="Data Source=Server;Initial Catalog=BO;User ID=WebUser;Password=333;Integrated Security=False"
    providerName="System.Data.SqlClient" />

GetNewConnection() から戻ると、次の例外が発生します

  • $exception {"オブジェクト参照がオブジェクトのインスタンスに設定されていません。"} System.Exception {System.NullReferenceException}

null参照を取得しているのはなぜですか?

4

2 に答える 2

4

UI プロジェクト、Your WEB Projectの Web.Config にConnectionStringが必要です。

そのセクションをコピーしてWeb.ConfigConnectionStringに貼り付けると、正常に動作するはずです

于 2012-08-06T14:31:24.980 に答える
3

接続文字列は、web.configではなくにある必要がありますapp.config

于 2012-08-06T14:31:02.153 に答える