为什么我不能通过.net中的sqlcinet连接到sql server 2008,但通过oledb我可以?

为什么我不能通过.net中的sqlcinet连接到sql server 2008,但通过oledb我可以?,.net,sql-server,.net,Sql Server,我有一个windows2008r2x64enterpriseedition+sqlserver2008r2datacenter版 从它的本地计算机,我可以通过C中的sqlClient连接到SQL服务器 这是我的连接字符串,看起来像: using (sqlconnection cn = new sqlconnection("Data Source=myServerIPAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myP

我有一个
windows2008r2x64
enterpriseedition+
sqlserver2008r2
datacenter版 从它的本地计算机,我可以通过
C
中的
sqlClient
连接到
SQL
服务器 这是我的连接字符串,看起来像:

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
注意:我也试过,但没有区别。

Hai,
请设置连接字符串的连接超时属性。

TCP/IP是否为Sql Server启用的连接协议?您可以在“Sql Server网络配置”下使用Sql Server配置管理器进行检查。

Windows 2008 Server从连接字符串中删除密码

您必须为您的连接指定密码
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
    }
}

您确定此代码正常工作吗?因为此代码有语法错误,例如在使用etcyeah时缺少“)”。代码正常工作,正如我所说,它在本地计算机上工作,但在任何远程计算机上工作,而oledb作为ConnectionString.com则表示sql server 2008的连接字符串中不存在超时属性。但不管怎样,我已经按照你在这里说的做了,谢谢你,它是有效的,但还有一个更大的问题:它太慢了!!!其中,oledb连接太快。我在某个地方读到过sqlclient比oledb快得多,但实际上完全相反。你知道这件事吗?关于。我认为Sql server有问题。请使用用户ID sa的正确权限为自己创建另一个用户。我在连接字符串中使用“sa”,sa对我所需的目录具有完全权限。我不知道如何进行任何进一步的更改,您能提供建议吗?感谢您可以在windows身份验证模式或SQL Server身份验证模式下创建新用户。首先转到数据库->安全->新用户TCP/IP也已启用。即使在创建了连接之后,检索数据也非常慢。