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

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!

5 answers

Hello

Try using \ instead of .
\ is the escape character of C# so for a string to contain a \ you must write \.

Thanks Max
It works... ofcourse.. sorry should have realized that myself... Thanks a lot! :)

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!

why you don't use @,
ex: string str=@"DataSource=.\SQLExpress......".

hope best try!

fotunaterly.

philong_thangthien16@yahoo.com

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.