连接到数据库时出错 [英] error while conncection to the database
问题描述
嗨
连接到服务器时,我发现了错误,但将不接受特殊字符.我尝试在特殊字符之前和之后使用%,然后它也会显示错误.
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.
string sqlConn = "Data Source=USER-PC%'"+\+"' %CompanyName';Initial Catalog=rack;User ID=trial;Password=trial112";
请解决此错误
Please solve this error
推荐答案
string sqlConn =@"Data Source=USER-PC;Initial Catalog=rack;User ID=trial;Password=trial112";
http://www.connectionstrings.com/ [ ^ ]
http://www.connectionstrings.com/[^]
尝试一下:
try this:
string sqlConn = "Data Source=USER-PC\\CompanyName;Initial Catalog=rack;User ID=trial;Password=trial112";
如果是本地PC,则将dot用作:
数据源= .; Ini .....
如果您在名称上苦苦挣扎,请尝试ping User-PC \ CompanyName ...
连接的语法为:
服务器\实例,端口
默认端口(SQL)-1433
确认可以连接.
初始化任何字符串时,请确保转义特殊字符.
\是特殊字符,您需要以\\
对其进行转义
谢谢,
Kuthuparakkal
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
string sqlConn = "Data Source=USER-PC\CompanyName;Initial Catalog=rack;User ID=trial;Password=trial112";
查看数据源值,该值应与打开sql服务器时在登录窗口中找到的值相同
例如
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!
:)
这篇关于连接到数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!