如何在 VS 2012 中使用 LocalDb 连接到旧的 sql 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15417483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I connect to an older sql database using LocalDb in VS 2012?
提问by ATL_DEV
I am trying to construct a connection string to a 2008 SQL Express database file in VS 2012. I am getting an error dialog:
我正在尝试在 VS 2012 中构建到 2008 SQL Express 数据库文件的连接字符串。我收到一个错误对话框:
This database file is not compatible with the current instance of SQL Server. To resolve this issue, you must upgrade the database file by creating a new data connection, or you must modify the existing connection to this database file. For more information, see http://go.microsoft.com/fwlink/?LinkId=235986
此数据库文件与 SQL Server 的当前实例不兼容。要解决此问题,您必须通过创建新数据连接来升级数据库文件,或者必须修改与此数据库文件的现有连接。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=235986
I followed the link to Microsoft's always wonderfully helpful documentation (cough, cough..). When I went through the upgrade database function, I was not presented with a prompt to upgrade the file. I was really hoping to use LocalDb instead of having to do a install of SQL Express 2008. Any thoughts?
我跟着链接到微软总是非常有用的文档(咳嗽,咳嗽......)。当我完成升级数据库功能时,我没有看到升级文件的提示。我真的希望使用 LocalDb 而不是必须安装 SQL Express 2008。有什么想法吗?
OTHER:Why hasn't Visual Studio implemented clicking on links in the error dialogs after all these years? Is it really hard to implement?
其他:为什么 Visual Studio 这么多年没有实现点击错误对话框中的链接?执行起来真的很难吗?
回答by OmiD
my simple way:
我的简单方法:
- go to VisualStadio 2012
- In Server ExplorerWindows
- open Data Connections
- Right click on ASPNETDB.MDF
- click on Modify Connection...
- a new windows open for you ... you just click OK
- if other windows open for you click Yes
- FINISH ( be Happy ) :D
- 前往VisualStadio 2012
- 在服务器资源管理器窗口中
- 打开数据连接
- 右键单击ASPNETDB.MDF
- 单击修改连接...
- 一个新窗口为您打开……您只需单击“确定”
- 如果其他窗口为您打开,请单击是
- 完成(快乐):D
回答by Leniel Maccaferri
From my experience of a few instants ago:
根据我前几天的经验:
Forget about trying to open the old
SQL Server Express
.mdf
file in Visual Studio 2012. During the conversion process of an old VS 2010 solution to VS 2012 it tells you can do that by just double clicking the database file and upgrade it to use LocalDb instead. That's a complete lie! :DOpen SQL Server Management Studio, select the
Databases
node, right click it and selectAttach...
.Provide the path for the
.mdf
file, click OK and then you should be good to go.Now inside
Visual Studio 2012
, openServer Explorer
(menuView -> Server Explorer
), right clickData Connections
and then selectAdd Connection...
. InServer name:
put(localdb)\v11.0
and inConnect to a database:
select the database you attached previously.Right click the
Data Connection
just added inSolution Explorer
and selectProperties
. Copy theConnection String
property and replace theWeb.Config
orApp.Config
one with this value.
忘记尝试
SQL Server Express
.mdf
在 Visual Studio 2012 中打开旧文件。在将旧 VS 2010 解决方案转换为 VS 2012 的过程中,它告诉您只需双击数据库文件并将其升级为使用 LocalDb 即可。那是彻头彻尾的谎言!:D打开SQL Server Management Studio,选择
Databases
节点,右键单击它并选择Attach...
。提供
.mdf
文件的路径,单击“确定”,然后您就可以开始使用了。现在在里面
Visual Studio 2012
,打开Server Explorer
(菜单View -> Server Explorer
),右键单击Data Connections
然后选择Add Connection...
。在Server name:
put(localdb)\v11.0
和 in 中Connect to a database:
选择您之前附加的数据库。右键单击
Data Connection
刚刚添加的Solution Explorer
并选择Properties
。复制该Connection String
属性并将Web.Config
或替换App.Config
为该值。
Note:In SQL Server Management Studio
I got an error while trying to attach an old .mdf
file I got from this sample project from DayPilot: Scheduler for ASP.NET MVC 4 Razor (C#, VB.NET, SQL Server). It was related to a path issue regarding the .log
file that accompanies the .mdf
database file. I just selected the .log
file entry in the Attach...
dialog window and removed it. Then tried to attach the database again and it worked.
注意:在SQL Server Management Studio
尝试附加.mdf
从 DayPilot: Scheduler for ASP.NET MVC 4 Razor (C#, VB.NET, SQL Server) 的示例项目中获得的旧文件时,我遇到了错误。它与有关数据库文件.log
随附文件的路径问题有关.mdf
。我刚刚.log
在Attach...
对话框窗口中选择了文件条目并将其删除。然后尝试再次附加数据库并且它起作用了。
回答by Jogai
You can just do:
你可以这样做:
USE [master]
GO
CREATE DATABASE [database_name] ON
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\<database name>.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\<database name>.ldf' )
FOR ATTACH ;
GO
As described here: http://technet.microsoft.com/en-us/library/ms165673%28v=sql.105%29.aspx
如此处所述:http: //technet.microsoft.com/en-us/library/ms165673%28v=sql.105%29.aspx
回答by Owaix Ansari
go to VisualStadio 2012 In Server Explorer Windows open Data Connections Right click on ASPNETDB.MDF click on Modify Connection... a new windows open for you ... you just click OK if other windows open for you click Yes
转到 VisualStadio 2012 在服务器资源管理器中 Windows 打开数据连接右键单击 ASPNETDB.MDF 单击修改连接...为您打开一个新窗口...如果其他窗口为您打开,您只需单击确定单击是
回答by hooman_b
open sql server management studio connect localDB remove deattach same name mdf file then attach your mdf file
打开sql server management studio连接localDB删除deattach同名mdf文件然后附加你的mdf文件
go to visual studio in server explorer-> dataconnection right click on your database -> modify connection -> text connection -> click OK
转到服务器资源管理器中的visual studio-> 数据连接右键单击您的数据库-> 修改连接-> 文本连接-> 单击确定