2011-10-21 30 views
0

我在Visual Studio 2010中創建了一個示例Web應用程序。它將成員數據(用戶,角色等)存儲在App_data文件夾中的.mdf文件中。但我不想這樣做。我想將數據存儲在SQL服務器數據庫中。ASP.NET成員數據存儲問題

爲此,我Google很多,但找不到解決方案。這是我所做的。首先,我創建應用程序,然後通過使用Web配置工具我設置用戶,角色等,並在被擊中時提供標籤,它拋出以下錯誤:

Could not establish a connection to the database. If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.

然後我執行aspnet_regsql公用事業和創建在SQL Server數據庫和再次打開網頁配置工具,但錯誤是一樣的,沒有變化。

請指導我是否正確或不正確。如果對的話我怎麼能把數據存儲在aspnet_regsql生成的SQL服務器數據庫中?

請注意,我使用的是.NET框架4,SQL Server 2008 R2,Visual Studio 2010.事實上,我期待着會有像web.config文件那樣的連接字符串,就像其他數據驅動控件一樣。但沒有條目進入web.config文件。

回答

0

通常情況下,asp.net成員資格用於sqlserver的大型應用程序。首先轉到web.config並註釋已存在的連接字符串,並添加連接到sqlserver和編目名稱的連接字符串。

<add name="ApplicationServices" 
    connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" 
    providerName="System.Data.SqlClient" /> 

<add name="ApplicationServices" connectionString="data source=servername;database name=databasename;user name= username; password=pass; 
    providerName="System.Data.SqlClient" /> 

替換它,然後在aspnet_regsql正常配置。這將確保演習。

+0

Nayyad在我的應用程序中沒有連接字符串已存在.config文件中。 – Khizar

+0

在配置標籤中添加一個,並在側面打開連接字符串標籤,並在其中放置上述代碼。 –