为什么我无法通过.net中的sqlcinet与sql server 2008建立连接,但使用oledb可以吗?
我有一个Windows 2008 R2 x64
企业版+ SQL Server 2008 R2
数据中心版 从本地电脑我可以在C#
连接到SQL
服务器sqlClient
,这里是我的连接字符串的样子:为什么我无法通过.net中的sqlcinet与sql server 2008建立连接,但使用oledb可以吗?
using (sqlconnection cn = new sqlconnection("Data Source=myServerIPAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"))
{
cn.open(); //I'll get error here from remote
using (sqlcommand cmd = new sqlcommand("sql",cn))
{
//some code here
}
}
但由于上面详细代码从远程计算机我会得到这个错误:
Timeout expired. The timeout period
elapsed prior to completion of the
operation or the server is not
responding.
但是当我改变上面的代码oledb一切工作正常。 分别oledb
不会改变连接字符串,这是我oledb
连接字符串:
Provider=SQLOLEDB;Data
Source=myserverIP;Password=password;User
ID=sa;Initial Catalog=catalog
注:我已经试过this,但也没有什么区别。
Hai, 请设置连接字符串的Connection Timeout属性。
作为connectionstrings.com表示没有超时attr存在连接字符串为sql server 2008. 但无论如何,我已经做了什么,我告诉过这里,并感谢它的工作原理,但有一个更大的问题:它是缓慢的地狱! oledb连接太快。 我读过的地方是sqlclient比oledb快,但实际上它完全是相反的。 你有什么想法吗? 关于。 – 2010-08-31 10:16:22
我认为Sql server有问题。使用正确的用户标识sa创建另一个用户。 – 2010-08-31 10:57:20
我在我的连接字符串中使用了“sa”,并且sa对我期望的目录具有完全权限我不知道如何进行任何进一步的更改,您能否提供建议? 谢谢 – 2010-08-31 11:31:56
TCP/IP是Sql-Server的启用连接协议吗?您可以在“Sql Server网络配置”下的Sql Server配置管理器中进行检查。
也启用TCP/IP。即使在创建连接之后,检索数据的速度也会很慢。 – 2010-08-31 10:35:31
Windows 2008服务器从连接字符串中去掉密码。
你要密码专门分配给您的连接cn
:
using (sqlconnection cn = new sqlconnection("Data Source=myServerIPAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"))
{
cn.password = "myPassword";
cn.open(); //I'll get error here from remote
using (sqlcommand cmd = new sqlcommand("sql",cn))
{
//some code here
}
}
你确定这个代码工作,因为这段代码有一个像“)”缺少使用等 – Kashif 2010-08-31 09:21:52
耶代码工作的语法错误,正如我所说的它的工作在本地但不是从任何远程计算机,因为与oledb它工作 – 2010-08-31 10:02:11