簡體   English   中英

connectionstring屬性尚未初始化-AppSettings

[英]The connectionstring property has not been initialized - AppSettings

以下是我的連接字符串,我不知道哪里出錯了。

<appSettings>

<!-- Default database to use... -->
<add key="Database_default" value="DB_Servername"/>

<!-- Datamart database connection to use -->
<add key="Database_datamart" value="MED_PROD"/>

<!--  Development Datamart Database Server -->
<add key="MED_PROD" value="Initial Catalog=REPORT_MED;Data Source=DB_Servername;UID=app_UID;PWD=******;"/>

<!--  Dev Server - Port Reference-->
<add key="va3fin01" value="Initial Catalog=acc;Data Source=DB_Servername;UID=med_UID;PWD=*******;"/>

<!-- MEDFIN_DEV -->
<add key="MED_DEV" value="Initial Catalog=MED_DEV;Data Source=DB_Servername;UID=med_UID;PWD=********;"/>

 </appSettings>

我無法更改任何后端代碼。 他們要求我更換服務器。 更改服務器后,我在運行的應用程序上得到“ connectionstring屬性尚未初始化”。 請讓我知道是否有什么我只能在web.config上處理的

請幫忙! 謝謝

編輯

下面是用於獲取連接字符串的方法。

private void GetConnectionString() 
    {
        string _settingname;

        // if its empty, update it with "default"
        if (this._database.Trim().Length == 0) this._database = "default";

        // get the setting...
        _settingname = ConfigurationSettings.AppSettings["Database_" + this._database];
        if (_settingname == null) 
        {
            throw new Exception("Unable to determine connection settings for specified database.");
        } 
        else
        {
            // retrieve the connection string from the specified database...
            this._ConnectionString = ConfigurationSettings.AppSettings[_settingname];
        }
    }

通常,連接字符串位於web.config的 connectionstring標記內。

例如,

<connectionStrings>
   <add name="MED_PROD" connectionString="Initial Catalog=REPORT_MED;Data Source=DB_Servername;UID=app_UID;PWD=******;" providerName="System.Data.SqlClient"/>
   <add name="va3fin01" connectionString="Initial Catalog=acc;Data Source=DB_Servername;UID=med_UID;PWD=*******;" providerName="System.Data.SqlClient"/>
   <add name="MED_DEV" connectionString="Initial Catalog=MED_DEV;Data Source=DB_Servername;UID=med_UID;PWD=********;" providerName="System.Data.SqlClient"/>
</connectionStrings>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM