question

HemanthB-9452 avatar image
0 Votes"
HemanthB-9452 asked Cathyji-msft commented

System.Data.SqlClient.SqlException: 'An attempt to attach an auto-named database for file "X" failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.'

Hi I am using WinAppSDK WinUI 3 framework. I created a Service Based-Database and in it I created a table. Now when I run the app I am getting this:
198389-image.png


sql-server-general
image.png (191.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @HemanthB-9452,

Any update for this thread? Did the reply(s) could help you? If the response helped, do "Accept Answer". If you have further question, please feel free to let us know.

0 Votes 0 ·
OlafHelper-2800 avatar image
0 Votes"
OlafHelper-2800 answered

I created a Service Based-Database

But in your connection string you use "AttachDbFilename" for a SQL Server User-Instance; not service based DB: it should be "Initial Catalog" or "Database" parameter instead.
And the error is raised, because the database (file) already exists in SQL Server.
See https://www.connectionstrings.com/sqlconnection/
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Cathyji-msft avatar image
0 Votes"
Cathyji-msft answered Cathyji-msft edited

Hi @HemanthB-9452,

According to your error message, please just to be sure check again your database server as it might already contain a database with the same name. Or please check if the file location of this database is correct.

In addition, please check if the parameters of your connection string is right. Please check below blog to get more.

An attempt to attach an auto-named database for file ....database1.mdf failed


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.