how do we translate my connection string from VB to Csharp

Hi,

Just place an@ sign before the string. Or use\\ to specify a single slash. This is because C# strings could contain format strings example is\n for newline.

Your connection string should look like this:

string myConn = @"workstation id=myPC;packet size=4096;integrated security=SSPI;data source=""myPC\LOCALHOST"";persist security info=False;initial catalog=myDataBase"

cheers,

Paul June A. Domag

[521 byte] By [PaulDomag] at [2007-12-22]
# 1

in my VB: myConn="workstation id=myPC;packet size=4096;integrated security=SSPI;data source=""myPC\LOCALHOST"";persist security info=False;initial catalog=myDataBase"

Csharp doesn t acept : ""myPC\LOCALHOST"" withing another string . How do I tuen that around to work in Csharp.


R.Tutus at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2

In C# as you've found you can't have a regular double quote inside of a string literal, instead to have a string there use it's escape character of \" so in C# your entire line would be:

myConn="workstation id=myPC;packet size=4096;integrated security=SSPI;data source=\"myPC\\LOCALHOST";persist security info=False;initial catalog=myDataBase";

You'll also notice that I doubled the \'s in the string 'myPC\\LOCALHOST'. This is needed because C# would have interpreted the presense of the \ to be an escape sequence and tried to use the following L for it, instead we use \\ to use the escape sequence to display a \ char.

Does this work for you?

BrendanGrant at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3

thanks a lot

any idea where I can find correspondance between Csharp and VB instructions and all syntaxes

thanks

R.Tutus at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# Language...
# 4

Hi,

In addition to that, if you want to not change anything in your connection string and leave the single slash as it is then you would place an @ operator before your string.

string myconn = @"you conn string \";

by placing an @ sign in your string, you would not have to place double '\' in your string.

cheers,

Paul June A. Domag

PaulDomag at 2007-8-30 > top of Msdn Tech,Visual C#,Visual C# Language...