简体   繁体   中英

How to access a database file with non mdf extension

Can we access a database file with non- .MDF extension using C#?

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:

An attempt to attach an auto-named database to file D:\\SQLExpress\\DB\\abc123tmp failed. A database of the same name exists, or specified file cannot be opened, or it is located at UNC share.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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