2013-10-19 72 views
0

我無法連接到SQL Server數據庫。無法使用Studio Express 2012 for web連接到SQL Server數據庫

當我運行aspnet_regsql.exe工具,我得到了以下錯誤消息:

Setup failed.

Exception:
Unable to connect to SQL Server database.

Details of failure

System.Web.HttpException: Unable to connect to SQL Server database. ---> System.Data.SqlClient.SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

另外,我無法使用ASP.NET網站管理工具。當我點擊安全標籤上我收到以下錯誤:

There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.

The following message may help in diagnosing the problem: Unable to connect to SQL Server database.

所以,我點擊「選擇數據存儲」按鈕的指示,這讓我選擇一個供應商。該提供者名爲'AspNetSqlProvider',它旁邊有一個測試鏈接。我點擊測試並收到以下錯誤信息:

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.

我已經失去了加班的這個問題,但我無法修復它。我希望每個人都可以幫助我。 我期待儘快收到良好的答覆。衷心感謝您的幫助。

+0

請參閱此問題http://stackoverflow.com/questions/9945409/how-doi-i-fix-the-error-named-pipes-provider-error-40-could-not-open-a-connec –

+0

您嘗試使用什麼**服務器(和實例)名稱**進行連接?看來你認爲存在的服務器確實不存在.... –

+0

你正在遠程開發嗎? –

回答

0

我遇到我的ASP.NET MVC項目,因爲,使用ASP.NET網站管理工具時,同樣的問題。解決方案是檢查並修改您的web.config文件。我只是改變以下屬性(添加一個字段):

1從

<profile> 
    <providers>...</providers> 

<profile defaultProvider="DefaultProfileProvider"> 
    <providers>...</providers> 

2)從

<membership> 
    <providers>...</providers> 

<membership defaultProvider="DefaultMembershipProvider"> 
    <providers>...</providers> 

3)從

<roleManager> 
    <providers>...</providers> 

<roleManager defaultProvider="DefaultRoleProvider"> 
    <providers>...</providers> 

而且,一定要有這樣的:

<connectionStrings> 
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20160111151822;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication1-20160111151822.mdf" /> 
</connectionStrings> 

"DefaultConnection"有下<profile><memebership>和相應字段connectionStringName="DefaultConnection"<roleManager>標籤,如上所述進行修改。

如果你仍然在你的MVC項目的問題,只需要創建一個新的完整的ASP.NET MVC Web應用程序模板,web.config文件和你比較,並修改你的web.config文件。

相關問題