是否可以在不使用SQL Server的情况下访问.mdf数据库? [英] Is it possible to access a .mdf database without SQL Server?

查看:76
本文介绍了是否可以在不使用SQL Server的情况下访问.mdf数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过SQL Server创建了一个 .mdf 文件,并将其放在本地文件中。我在没有安装SQL Server的计算机上运行程序。而且我还使用了 System.Data.SqlClient 命名空间中的类(即 SqlConnection ..)

I created a .mdf file by SQL Server and put it to a local file. I run my program in a computer which has no SQL Server installed. And also I used classes from the System.Data.SqlClient namespace (i.e. SqlConnection..)

我想与由SQL Server创建的 .mdf 文件建立某种访问连接吗?

I want to make some kind access connection with .mdf file which was created by SQL Server? Is it possible ?

推荐答案

我认为不通过SQL Server引擎就无法与MDF文件进行交互。您很可能会安装SQL Server Express(如果选择通过Visual Studio的添加/删除程序,则应该选择该选项,也可以从此处单独下载-这是带有工具的2008 R2选项),附加数据库,然后从程序连接到该引擎。

I don't think it is possible to interact with an MDF file without going through a SQL Server engine. You would most likely install SQL Server Express (which should be an option if you choose to go through add/remove programs for Visual Studio, or you can download it separately from here - this is the 2008 R2 With Tools option), attach your database, and then connect to that engine from your program.

许多在线教程会建议您使用用户实例功能和 AttachDbFileName 。我建议您不要走那条路,因为这经常会造成混乱-许多很多用户通过Management Studio连接到数据库的一个实例,而不是他们程序中的另一个实例,然后不要了解为什么一个人看不到另一个人所做的更新。 用户实例功能已被弃用,我非常希望将数据库正确地附加到实例。

Many tutorials online will suggest you use the User Instances feature and AttachDbFileName. I suggest you don't go that route as it often leads to confusion - many, many users connect to one instance of the database through Management Studio, a different instance from their program, and then don't understand why one doesn't see the updates made by the other. The User Instances features is deprecated and I highly prefer attaching a database to the instance properly.

在SQL Server 2012中您可以下载新的 SqlLocalDb 运行时(您要从此处获取x86或x64 SqlLocalDB.MSI文件),这使此过程更加容易,因为它不是维护按需SQL Server引擎。不过请注意,您的数据库将升级为新的11.0文件格式,这意味着您将无法分离/附加或备份/还原到旧版本(2008、2008 R2等)。我添加了许多针对新用户的故障排除技术,从SqlLocalDb在这里

In SQL Server 2012 you can download the new SqlLocalDb runtime (you want either the x86 or x64 SqlLocalDB.MSI file from here), which makes this process much easier, as it is a no-maintenance on-demand SQL Server engine. However note that your database will be upgraded to the new 11.0 file format, which means you won't be able to detach/attach or backup/restore to an older version (2008, 2008 R2, etc). I added many troubleshooting techniques for new users starting with SqlLocalDb here.

这篇关于是否可以在不使用SQL Server的情况下访问.mdf数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆