2013-01-03 50 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