Click here to Skip to main content
11,648,455 members (80,491 online)
Rate this: bad
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 19:54pm
Edited 26-Aug-12 20:08pm
Mehdi Gholam282.9K
Zoltán Zörgő at 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
0 F-ES Sitecore 395
1 DamithSL 305
2 OriginalGriff 297
3 CPallini 250
4 Kornfeld Eliyahu Peter 180
0 OriginalGriff 1,342
1 994
2 DamithSL 981
3 Sergey Alexandrovich Kryukov 893
4 CPallini 845

Advertise | Privacy | Mobile
Web02 | 2.8.150804.4 | 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