Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
while connection to the server i found the error , it will not accept special characters. i tried using % before and after the special character then also it showing errors.
C#
string sqlConn = "Data Source=USER-PC%'"+\+"' %CompanyName';Initial Catalog=rack;User ID=trial;Password=trial112";

Please solve this error
Posted
Updated 26-Aug-12 20:08pm
v2
Comments
Zoltán Zörgő 27-Aug-12 2:09am    
I suppose the USER-PC is the machine running the SQL server, but is the CompanyName the fixed instance name of the SQL server as you see it in the service manager, or is it a variable? In the second case you mean that the USER-PC machine is running several different instances of SQL server?

C#
string sqlConn =@"Data Source=USER-PC;Initial Catalog=rack;User ID=trial;Password=trial112";

http://www.connectionstrings.com/[^]
 
Share this answer
 
v2
try this:
C#
string sqlConn = "Data Source=USER-PC\\CompanyName;Initial Catalog=rack;User ID=trial;Password=trial112";


If it's local PC, use dot as :

"Data Source=.;Ini.....

If you are struggling with name try to ping User-PC\CompanyName...

The syntax of connection is:

Server\Instance, Port
Default port(SQL) - 1433

Verify you can connect.

When you initialize any string make sure that escape special charcters..
\ is a special charcater and you need to escape it as \\

Thanks,

Kuthuparakkal
 
Share this answer
 
v3
string sqlConn = "Data Source=USER-PC\CompanyName;Initial Catalog=rack;User ID=trial;Password=trial112";


see data-source value it should be same as you find in login window while open your sql server
e.g.
'server name' = xyz\SQLEXPRESS

then
connection string should like below
string sqlConn = "Data Source=xyz\SQLEXPRESS;Initial Catalog=rack;User ID=trial;Password=trial112";


Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900