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

来源:互联网 发布:mac系统游戏 编辑:程序博客网 时间:2024/05/21 08:10

解决无法在高版本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

0 0