0

I have a Windows Forms application written in C# using SQL Server 2012 Express as its database.

I need a connection string to work on any PC.

I try to put the .mdf file in DataDirectory or drive C: or C:\ProgramData

DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mydb.mdf;Pooling=False;

In this case the error is:

Failed to update .mdf database because the database is read-only

If I try to use

user instance=True; 

in the connection string, I get the following error :

System.Data.SqlClient.SqlException (0x80131904): Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

If I try to put the .mdf file in user application data AppRoaming folder it's not supported and returns error :

An attempt to attach an auto-named database for file failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

So how to set my connection string and where should the .mdf file be stored?

Please help me

And thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Moayad Myro
  • 294
  • 1
  • 3
  • 12

0 Answers0