从 VB 2008 Express 连接到 SQL Server 2008 Express
我在我们的大学项目中使用 VB 2008 Express。我还运行 SQL Server 2008 Express,并安装了 SQL Server Management Studio 并使用它来创建我的数据库。
这两个软件均已在本地安装并运行。我正在尝试从 VB 2008 Express 连接到数据库。数据库连接向导有 3 个选项:
- 连接到 Access 数据库、
- 连接到 SQL Server 3.5 紧凑数据库和
- 连接到 SQL Server 数据库文件。
连接到前两个没有问题,但是当我尝试连接到 SQL Server 数据库文件 (.mdf) 时,它会抛出以下错误(“无法打开物理文件......操作系统错误 32:(未能检索此错误的文本。原因:1815......尝试附加文件 .......mdf 的自动命名数据库失败。存在同名的数据库,或无法指定指定的文件。打开,或者它位于 UNC 共享上”)
如果任何有相同经历并克服问题的人能够为我指明正确的方向,我将不胜感激。
非常感谢。 小动物。
I'm using VB 2008 Express for our College Project. I'm also running SQL Server 2008 Express and have installed SQL Server Management Studio and used it to create my database.
Both software have been installed and running locally. I'm trying to connect to the database from VB 2008 Express. Database connection wizard have 3 options:
- connecting to Access db
- connecting to SQL Server 3.5 compact db and
- connecting to SQL Server db file.
There are no problems connecting to the first two but when I try to connect to my SQL server DB file (.mdf) it throws the following error ("Unable to open the physical file .... Operating system error 32:(failed to retrieve text for this error. reason:1815.......an attempt to attach an auto-named database for file ...... .mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share")
I appreciate if anyone who had the same experience and overcome the problem could point me in the right direction.
Thanks very much.
Little Critter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将数据库与服务器分离。由于您在那里创建了该文件,因此它已经在 SQL Express 服务器上运行。操作系统错误 32 是共享冲突,这意味着该文件正在使用中。
试试这个:
您的数据库应该与数据库服务器分离。现在服务器将不再自动启动该数据库,您应该能够获得对它的独占访问权限。
请注意,如果您想对 MDF 进行更多编辑,则必须重新连接数据库,或者需要使用 VB 2008 Express 中内置的工具。因此,大多数人会选择保留数据库,而不是将其作为“用户实例”运行。查看此链接,了解获取数据的其他方法:如何:访问和初始化服务器资源管理器/数据库资源管理器。
不管怎样,你可能有你这样设置的理由。上述步骤应该可以解决您的问题。祝你的项目好运!
You need to detach your database from the server. Since you created the file there it is already running on the SQL Express server. Operating System Error 32 is a sharing violation and it means that the file is in use.
Try this:
Your database should detach from the database server. Now the server will no longer bring that database up automatically and you should be able to get exclusive access to it.
Note that if you want to make more edits to the MDF you will have to reattach the database or you will need to use the tools built into VB 2008 Express. Because of this most people would choose to leave the database attached and not run it as a "User Instance". Check out this link for alternative ways to get to your data: How to: Access and Initialize Server Explorer/Database Explorer.
Anyway, you may have your reasons for setting it up this way. The steps outlined above should fix you up. Good luck with your project!