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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 problem in connection string

Author  Topic 

Exir
Posting Yak Master

151 Posts

Posted - 2010-11-12 : 10:20:57
Hi

This is my connection string:

SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\db.mdf;Integrated Security=True;user Instance=True");
cn.Open();


It can not connect to database when i use it in my program and send this error:

quote:

Unable to open the physical file "C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\db.mdf". Operating system error 5: "5(error not found)".
An attempt to attach an auto-named database for file C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\db.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.



where is the problem in my connection? and which part of my program should be rechecked?

thank u

Sachin.Nand

2937 Posts

Posted - 2010-11-12 : 11:48:24
Check ur connectionstring syntax below

http://www.connectionstrings.com

PBUH

Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2010-11-12 : 12:06:30
I used "Data Source=ZY-PC\\SQLEXPRESS" instead of "Data Source=.\SQLEXPRESS" and the problem resolved while i use "." or ".\SQLEXPRESS" in other programs, could you please explain a little about data source and when we should use which data source ?
thanks a lot
Go to Top of Page
   

- Advertisement -