Hi,
I'm trying to set up a connection string to a simple SQL Express database file
but I keep getting an error.
I copied this string from the Database object in the Database explorer. I changed the slashes to forward slashes to get rid of the escape sequence issue & changed the timeout & Integrated seccurity but apart from that it's the same.
The file is in the same directort as the Solution so I guess you can say it's Local.
Any ideas on a correct conenction string would be most appreciated
Thanks very much in advance
Ant
Code Snippet
string conString = "Data Source=./SQLEXPRESS;"
+ "AttachDbFilename="
+ "'C:/Documents and Settings/aklune/My Documents/Visual Studio 2005/Projects/WindowsApplication1/WindowsApplication1/test.mdf';"
+"Integrated Security=True;"
+ "Connect Timeout=10;"
+"User Instance=True;";
SqlConnection con = new SqlConnection(conString);
con.Open();
con.Close();
Hi,have a look on this site for connectionstring related issues.
http://www.connectionstrings.com/?carrier=sqlserver2005
Zafar Iqbal|||Did you try to use theSQLConnectionStringBuilder ?
Code Snippet
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder();
sb.DataSource = ".\\SQLEXRESS";
sb.UserInstance = true;
sb.AttachDBFilename = @."C:\Documents and Settings\aklune\My Documents\Visual Studio 2005\Projects\WindowsApplication1\WindowsApplication1\test.mdf"
sb.IntegratedSecurity = true;
sb.ConnectTimeout = 10;
string COnnecitonString = sb.ToString();
You don′t need to escape the characters if you use the @. sign before the quote for your string.
Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||Hello Jens,
Thank you very much for your help there. I didn't know about the ConnectionStringBuilder or the @. sign. Both great tips.
The issue still persists though.
The error is:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
The database file is located on the local machine as suggested by the Filename path so I'm not sure that it's a "Remote connection". I'm not sure if this is just a generic error.
I have checked that the file exists for that location & I used the code you supplied as a test but I still get the above error.
Is there anything else I might need to check?
Many thanks again
Ant
|||You need to verify that you indeed have a running SQL Server.|||Hi Arnie,
Thanks for your answer.
I am running SQLSERVER 2005 Express edition. How can I tell if it is 'running'?
If I open SQL2K5 Xpress, I can run queries against the db's & things look fine, but even if it is open, I still cannot connect VS2005.
Does SQL2005 actually need to be 'Open' to be running? I shouldn't think think so.
When I try another approach of adding a New Data Source from within VS2005 data sources tab, when I navigate to the MDF file & choose it then test the conenction , I get the error:
"Generating User instances in SQL2005 is disabled".
However I still get the error after running sp_Configure 'User instances enabled' SP.
Thanks for your ongoing help on this one. I just can't seem to get a conenction happening.
Maybe it's not possible to conenct to SQL2005 Express?
Thanks very much for your help here
@.nt
No comments:
Post a Comment