Developers community number 1 connection string reference

C# reads \ as new line when using connection string for ServerName\SQLEXPRESS

Posted 2010-04-21 14:44
by Michael Gray
in the SQL Server Forum
Hi

Thanks for the best website and it really helps, but I have question.

I am coding my Project using .Net and C# and My database is SQL Server 2005.
When I connect by using connection string = ServerName\SQLEXPRESS it does not read instead it gives me Error because C# read \ as next line but it works when I am using VB.Net...
My Server Name is Michael-PC\SQLEXPRESS
I tried to use connection string = DataSource(Local) and it doesn't work either... Can anyone Please Help?

Thanks!
Reply 2010-04-21 14:46
by Max Wikström
in the SQL Server Forum
Hello

Try using \\ instead of \.
\ is the escape character of C# so for a string to contain a \ you must write \\.
Reply 2010-04-21 14:47
by Michael Gray
in the SQL Server Forum
Thanks Max
It works... ofcourse.. sorry should have realized that myself... Thanks a lot! :)
Reply 2010-05-03 08:57
by Nilesh Chauhan
in the SQL Server Forum
Thank you very much.....sir/mam
Actually i was suffering from this problem for last night.........but due to your sight i got able to get rid over this problem...........thanks a lot!
Reply 2010-05-29 14:47
by hai dt
in the SQL Server Forum
why you don't use @,
ex: string str=@"DataSource=.\SQLExpress......".

hope best try!

fotunaterly.

philong_thangthien16@yahoo.com
Reply 2010-08-27 05:28
by tamilalagan vilvanathan
in the SQL Server Forum
Instead of using the servername use ".//SQLEXPRESS" in data source column.
And I am having a doubt how we can create a database in user selected path....

For example i want to create my database in "d:\"
Please help me.

Thanks.
Copyright © 2012 ConnectionStrings.com   |   All Rights Reserved   |   Powered by CSAS   |   Send feedback, articles, requests and more connection strings here.