2011-11-09 12 views
1

我正在使用Web部件創建儀表板頁面。要做到這一點,我動態加載webparts。由Web部件導致的SQL Server錯誤

strZoneNumber = "zone" + intCnt.ToString(); 
UserControl UC = (UserControl)LoadControl(row["c_widget_path"].ToString());//Loads the usercontrol 
UC.ID = row["c_widget_webid"].ToString(); 
UC.Attributes.Add("Title", row["c_widget_webid"].ToString()); 
//UC.Attributes.Add("title" , "Test"); 
GenericWebPart ucwebPart = wpmDashBoardManager.CreateWebPart(UC);//creates a webpart 
wpmDashBoardManager.AddWebPart(ucwebPart, wpmDashBoardManager.Zones[strZoneNumber], ZoneIndex);//adds it to a zone 
wpmDashBoardManager.Zones[strZoneNumber].Visible = true; 

我WebPartManager的個性化模式設置爲「真」

雖然它給我下面的錯誤在服務器上運行此頁:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

SQLExpress database file auto-creation error: The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

如果應用程序App_Data目錄不已存在,則Web服務器帳戶必須具有對應用程序目錄的讀取和寫入權限。這是必要的,因爲如果Web服務器帳戶尚不存在,它將自動創建App_Data目錄。

如果應用程序App_Data目錄已經存在,則Web服務器帳戶只需要對應用程序App_Data目錄進行讀寫訪問。這是必要的,因爲Web服務器帳戶將嘗試驗證Sql Server Express數據庫已經存在於應用程序的App_Data目錄中。從Web服務器帳戶撤銷對App_Data目錄的讀取訪問將阻止提供者正確確定Sql Server Express數據庫是否已存在。當提供者試圖創建已經存在的數據庫的副本時,這將導致錯誤。寫訪問權限是必需的,因爲在創建新數據庫時使用了Web服務器帳戶憑證。

Sql Server Express必須安裝在機器上。 Web服務器帳戶的進程標識必須具有本地用戶配置文件。有關如何爲機器和域帳戶創建本地用戶配置文件的詳細信息,請參閱自述文檔。**

有關可能導致此問題和解決方案的任何想法?幫助將不勝感激:) :)

回答

3

ASP.NET的許多功能依賴於內部應用程序服務,如成員資​​格,角色,配置文件和個性化。例如,ASP.NET個性化服務使用個性化提供程序來保存Web頁面上的個性化用戶設置。默認情況下,Web部件嘗試將個性化設置保存到SQL Express數據庫中。

這個解決方案對我來說很有幫助。

在web.config文件的connectionStrings節刪除LocalSqlServer連接,並與自己的喜好重新添加它:

<connectionStrings> 
    <remove name="LocalSqlServer"/> 
    <add name="LocalSqlServer" connectionString="yourConnectionString" providerName="System.Data.SqlClient"/> 
</connectionStrings> 

然後,如果你將有「未能找到存儲過程‘dbo.aspnet_CheckSchemaVersion’的錯誤你應該爲您創建一個新的數據庫用於個性化。 因此,只需探索C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe並完成嚮導的步驟。

希望它會有所幫助。