简体   繁体   English

如何访问具有非mdf扩展名的数据库文件

[英]How to access a database file with non mdf extension

Can we access a database file with non- .MDF extension using C#? 我们可以使用C#访问具有非.MDF扩展名的数据库文件吗?

We are creating a setup project. 我们正在创建一个安装项目。 We don't want the user to know the database details which is installed in the installation folder. 我们不希望用户知道安装文件夹中安装的数据库详细信息。 So, I have tried renaming the database data file and log file with a random name without any extension. 因此,我尝试使用不带任何扩展名的随机名称重命名数据库数据文件和日志文件。

When I have tried accessing the file from c# we are getting an error like: 当我尝试从C#访问文件时,出现如下错误:

An attempt to attach an auto-named database to file D:\\SQLExpress\\DB\\abc123tmp failed. 尝试将自动命名的数据库附加到文件D:\\ SQLExpress \\ DB \\ abc123tmp。 A database of the same name exists, or specified file cannot be opened, or it is located at UNC share. 存在相同名称的数据库,或者无法打开指定的文件,或者该文件位于UNC共享中。

Can anyone help me solve the issue? 谁能帮我解决这个问题?

Start SSMS, connect to (localDb)\\MSSQLLOCALDB and look at the Databases attached ... I guess the File you want to attach is already attached under a different name. 启动SSMS,连接到(localDb)\\ MSSQLLOCALDB并查看附加的数据库...我想您要附加的文件已经以其他名称附加了。 Detach that instance first and then your Connection should work. 首先分离该实例,然后您的连接应该工作。 It's not possible to attach the same File using different Database names. 无法使用不同的数据库名称附加相同的文件。 The File Extension does not matter. 文件扩展名无关紧要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM