数据库应该在哪里用于此代码?

时间:2013-01-03 02:45:29

标签: c# asp.net sql-server visual-studio-2010 mdf

我有以下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。

(请注意,这个项目是由另一个人完成的,我试图了解数据库的位置。谢谢)

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

简而言之:确保您的计算机上正在运行默认的SQL实例(主要是名为.\SQLEXPRESS的快速版本)。看起来您的计算机上没有设置默认的SQL实例。

您可以通过SSMS工具进行检查。这是一个关于 - SQL Server Management Studio (SSMS) Basics的链接。

相关帖子 - Cannot register default instance MSSQLSERVER in SQL Server 2008