SQLExpress \ character in c# string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am using System.Diagnostics,Process.Start
to execute sqlcmd.exe
the second parameter of the Start method is the arguements to pass to sqlcmd

Because I am using SQLExpress the string contains "MachineName\\SQLExpress"

the \\ is there becase of escape clauses, etc.

It is causing my method to fail.

How do I go from \\ to \ in a string so I can pass the string as a parameter
to the Start method??

I have played with @"" string literals and string.format and \u0000 but I am
getting nowhere

your help appreciated


string sSQLcmd = string.Format(@"-S {0} -d {1} -i ""Tables Functions
Sprocs.sql"" -o ""SQL Script1 Output.txt""", sSQLdataSource, sSQLdataBase);

where sSQLdataSource = "machineName\\SQLexpress"

so I can

Process p = Process.Start("sqlcmd", sSQLcmdArguement);

Thanks
Charlie
Sydney
Oz
 
Have you tried quoting the argument? i.e.

string.Format(@"-S ""{0}"" -d [etc as before]

If that doesn't work... simply dump the complete string to a file
(File.WriteAllText()) or the clipboard (Clipboard.SetText()) so that
you can see *exactly* what you have actually got, without the IDE
confusing you with combinations of @, \, \\, etc... compare this to
what you would have at the (working) command-line.

Marc
 
Hi,

I am using System.Diagnostics,Process.Start
to execute sqlcmd.exe
the second parameter of the Start method is the arguements to pass to sqlcmd

Because I am using SQLExpress the string contains "MachineName\\SQLExpress"

the \\ is there becase of escape clauses, etc.

It is causing my method to fail.

How do I go from \\ to \ in a string so I can pass the string as a parameter
to the Start method??

I have played with @"" string literals and string.format and \u0000 but I am
getting nowhere

your help appreciated


string sSQLcmd = string.Format(@"-S {0} -d {1} -i ""Tables Functions
Sprocs.sql"" -o ""SQL Script1 Output.txt""", sSQLdataSource, sSQLdataBase);

where sSQLdataSource = "machineName\\SQLexpress"

so I can

Process p = Process.Start("sqlcmd", sSQLcmdArguement);

Thanks
Charlie
Sydney
Oz

Don't store the \\ in the connection string. Store it in the usual
manner. I suspect the IDE is the one confusing you the way it displays
the string
 
Back
Top