Click here to Skip to main content
11,922,641 members (30,762 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# sqldatasource

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.
string sqlConn = "Data Source=USER-PC%'"+\+"' %CompanyName';Initial Catalog=rack;User ID=trial;Password=trial112";
Please solve this error
Posted 26-Aug-12 20:54pm
Edited 26-Aug-12 21:08pm
Mehdi Gholam292.4K
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?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

string sqlConn =@"Data Source=USER-PC;Initial Catalog=rack;User ID=trial;Password=trial112";[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

try this:
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 \\


Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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
'server name' = xyz\SQLEXPRESS
connection string should like below
string sqlConn = "Data Source=xyz\SQLEXPRESS;Initial Catalog=rack;User ID=trial;Password=trial112";

Happy Coding!
Smile | :)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151125.1 | Last Updated 27 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100