2013-01-03 86 views
0

我有包含的代碼如下如下web.config文件:該代碼的數據庫應該在哪裏?

<connectionStrings> <add name="CustomerManagementConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|CustomerManagement.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" /> <add name="Entities" connectionString="metadata=res://*/App_Code.CustomerManagement.csdl|res://*/App_Code.CustomerManagement.ssdl|res://*/App_Code.CustomerManagement.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CustomerManagement.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" /> </connectionStrings>

然而,當我運行Visual Studio的Web應用程序項目,它給我以下內容:

 
Server Error in '/CustomerManagement' Application. 
-------------------------------------------------------------------------------- 

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed. 
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. 

Exception Details: System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed. 

以前,它給我以下錯誤消息,我通過安裝SQL Express Edition 2005來解決此問題。

 

Server Error in '/CustomerManagement' Application. 

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. 

Exception Details: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 

所以,我想知道哪個數據庫,如果錯誤指的是。它是指SQL Server中的數據庫還是位於項目文件中的mdf。

(請注意,這個項目是由其他的人,我想明白的地方數據庫,謝謝。)

回答

0

簡而言之:請確保您的默認SQL實例(主要是快遞版叫.\SQLEXPRESS)在您的計算機上運行。它看起來像你的機器上沒有設置默認的SQL實例。

您可以通過SSMS工具檢查。這是鏈接 - SQL Server Management Studio (SSMS) Basics

相關崗位 - Cannot register default instance MSSQLSERVER in SQL Server 2008

+0

實際上。\ SQLEXPRESS已經與其他SQL實例一起運行。順便說一下,如何檢查。\ SQLEXPRESS是否爲默認的SQL實例? – Jack

+0

@Jack,我已將它發佈在我的答案上。 –

1

嘗試刪除以下目錄的內容:

C:\Users\<user name>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS.

(將<user name>替換爲您當前登錄的帳戶。)

有關更多信息,請參閱:Error: Failed to generate a user instance of SQL Server

+0

感謝moncadad,它給我的另一個錯誤 - '數據庫「d:\ LABFILES \ APP_DATA \ CUSTOMERMANAGEMENT.MDF」不能打開,因爲它是655這個版本的服務器支持版本611和更早。降級路徑不受支持。 無法打開新數據庫'D:\ LABFILES \ APP_DATA \ CUSTOMERMANAGEMENT.MDF'。 CREATE DATABASE被中止。 嘗試附加文件D:\ LABFILES \ APP_DATA \ CustomerManagement.mdf的自動命名數據庫失敗。存在相同名稱的數據庫,或者指定的文件無法打開,或者位於UNC共享上。「 – Jack

+0

看起來它可能是SQL Server 2005和2008兼容性問題。嘗試從App_Data文件夾中刪除.MDF和.LDF文件。他們應該在重新編譯後重新創建。 **確保你先備份你的MDF文件! ** –

+0

順便說一句,我不明白爲什麼這是'C:\用戶\ \應用程序數據\本地\微軟\ Microsoft SQL Server數據\ SQLEXPRESS'文件夾在那裏。該文件夾在那裏有目的嗎? – Jack