Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rlthomas3
Starting Member
2 Posts |
Posted - 2009-09-14 : 15:18:14
|
| HELP!Having problem connecting to SQL Server database in C# project. I can connect just fine via Server Explorer in Visual Studio and Server Management Studio. When I run my project I get:Error: 18456, Severity: 14, State: 38.2009-09-13 23:23:44.77 Logon Login failed for user 'Ronnie-PC\Ronnie'. Reason: Failed to open the explicitly specified database. [CLIENT: ]My connection string : conn = new SqlConnection("Data Source=Ronnie-PC\\SQLEXPRESS;Initial Catalog=BQQ.mdf;Integrated Security=True;");I'm using windows authentication and remote login access is enabled. Any help would be greatly appreciated. |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-09-14 : 16:13:07
|
| Is the DB you're trying to connect to called BBQ ? If so, change the initial Catalog to just BBQ (drop the .mdf). In other words just use the DB name not the mdf file.Be One with the OptimizerTG |
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2009-09-14 : 16:56:59
|
| For .net c# its ok to use the mdf file name, e.gServer=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;But reason why its not working is that in c# you have to either use1. a period before the instance name ie .\SQLExpress;2. You have to use the @ sign if you are using one slash , but since you are using two, its ok. |
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2009-09-14 : 16:59:05
|
| see this alsohttp://connectionstrings.com |
 |
|
|
rlthomas3
Starting Member
2 Posts |
Posted - 2009-09-15 : 15:52:38
|
| Thanks for your inputs! The string that worked for me is: conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\BQQ.mdf;Integrated Security=True;User Instance=True");Greatly appreciate all the help! |
 |
|
|
|
|
|