解决方案——Connect to an old database using LocalDB in VS

解决无法在高版本VS中连接低版本SQlServer数据库文件的问题

当我们尝试在高版本VS中将一个低版本SQLServer数据库文件添加到模型中的时候,可以会得到这样一个提示:

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

然后我们又不得不发现Microsoft上得不到直接有用的解决方案。

其实我们可以这样做:
1.打开SQL Server Management Studio,添加目标数据库文件。
2.在VS中打开Server Explorer(View -> Server Explorer),新建数据库连接至刚刚导入SQLServer的库,Server name置为(localdb)\v11.0
3.点击我们刚刚添加的Data Connection,选择Properties,将Connection String的值替换Web.config中的数据库连接信息。
4.在Models文件夹中添加Models,选择我们刚刚建立的连接信息,发现可以成功了!

以下引自stackoverflow原文:

1.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! :D
2.Open SQL Server Management Studio, select the Databases node, right click it and select Attach….
3.Provide the path for the .mdf file, click OK and then you should be good to go.
4.Now inside Visual Studio 2012, open Server Explorer (menu View -> Server Explorer), right click Data Connections and then select Add Connection…. In Server name: put (localdb)\v11.0 and in Connect to a database: select the database you attached previously.
5.Right click the Data Connection just added in Solution Explorer and select Properties. Copy the Connection String property and replace the Web.Config or App.Config one with this value.
——see here

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值