如何在不安装SQL Server前preSS版添加在Visual Studio中的SQL Server数据库文件(.MDF)?数据库文件、如何在、Server、SQL

2023-09-02 10:52:00 作者:别跟我磨叽i

我下面在Visual Studio 2010中的项目加入 .MDF 文件(SQL Server数据库)中的错误

I have an error below adding an .mdf file (SQL Server Database) in a Visual Studio 2010 project

连接到SQL Server数据库文件(.mdf)要求的SQL Server   2005年防爆preSS或SQL Server 2008前preSS安装并运行   本地计算机

Connections to SQL Server database files (.mdf) require SQL Server 2005 Express or SQL Server 2008 Express to be installed and running on the local computer

我不想安装SQL Server前preSS(2005/2008),因为我已经安装了 SQL Server 2005企业版

I don't want to install SQL Server Express (2005/2008) because I have already installed SQL Server 2005 Enterprise Edition

我在使用Visual Studio 2010旗舰版

I am using Visual Studio 2010 Ultimate

推荐答案

这是一个非常烦人的。基本上,在Machine.config中为您正在开发针对该框架的版本,对于LocalSqlServer的条目。

This is a really annoying one. Basically, in Machine.config for the version of the framework you are developing against, there is an entry for LocalSqlServer.

在我的机器上,4版:

C: WINDOWS Microsoft.NET 框架 v4.0.30319 CONFIG Machine.config中

C:WindowsMicrosoft.NETFrameworkv4.0.30319ConfigMachine.config

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

我发现,如果我改变了连接字符串的数据源部分指向我的SQL 2005完整的服务器实例,那么你提到的错误就走开了。

I found that if I changed the data source part of the connection string to point at my Sql 2005 full server instance, then the error you mentioned went away.

(类似的其他版本的框架,这也是我改变了)

(Similar for other versions of the framework, which I also changed)

如果我需要重启动Visual Studio或整台机器之前,我看到了变化工作,我不记得了。

I can't remember if I needed to restart just visual studio or the whole machine before I saw the changes work.

记住要备份编辑前您的Machine.config文件!

Remember to back up your machine.config files before editing them!

有了这样说,但也没有理由你可以通过查看数据库不添加到SQL Server本身(如果你有MDF),然后从Visual Studio连接到它 - >服务器资源管理器 - >数据连接(右键 - >添加连接) - 你试过了

With that being said, there's also no reason why you can't add the database into Sql Server itself (if you have the mdf) then connect to it from Visual Studio via the View -> Server Explorer -> Data Connections (Right Click -> Add Connection) - have you tried that?