Can't seem to connect to a .mdf file (SQL express) that is NOT located in app_code

J

John Shelley

The connection string is just as I see it documented in dozens of
places:

S =
"Server=.\SQLExpress;AttachDbFilename=C:xxx.mdf;Database=xxx;Trusted_Con
nection=Yes;"

Yet, the connection fails.

Am i missing something obvious?

-zorpie
 
J

Jason Keats

John said:
The connection string is just as I see it documented in dozens of
places:

S =
"Server=.\SQLExpress;AttachDbFilename=C:xxx.mdf;Database=xxx;Trusted_Con
nection=Yes;"

Yet, the connection fails.

Am i missing something obvious?

-zorpie


I detached one of my databases, then used your connection string (with a
full path to the .mdf file) to create a SqlConnection (and retrieve
data) without problems.


Normally, however, I would just restore/attach my database (using
Microsoft SQL Server Management Studio Express), then use one of the
following connection strings:

sCnn = "Data Source=MyServer;Initial Catalog=MyDB;User
Id=MyUser;Password=MyPassword;"

sCnn = "Server=MyServer;Database=MyDB;User
ID=MyUser;Password=MyPassword;Trusted_Connection=False;"

sCnn = "Data Source=MyServer;Initial Catalog=MyDB;Integrated Security=SSPI;"

sCnn = "Server=MyServer;Database=MyDB;Trusted_Connection=True;"

sCnn = "Server=MyServer\SQLEXPRESS;Database=MyDB;Trusted_Connection=True;"

sCnn = "Server=MyServer;Database=MyDB;User
ID=sa;Password=MyPassword;Trusted_Connection=False;Packet Size=4096;"

sCnn = "Data Source=127.0.0.1,1433;Network Library=DBMSSOCN;Initial
Catalog=MyDB;User ID=MyUser;Password=MyPassword;"

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top