开发者

Why I am not able to make a connection to a sql server 2008 via sqlcinet in .net but with oledb I can?

I have a Windows 2008 R2 x64 enterprise edition + SQL Server 2008 R2 datacenter edition from its local computer I can make connection to the SQL server with sqlClient in C# and here is my connection string looks like :

using (sqlconnection cn = new sqlconne开发者_运维百科ction("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
    }
}

but with exact above code from a remote computer I'll get this error :

Timeout expired.  The timeout period
elapsed prior to completion of the
operation or the server is not
responding.

but when I change above code to oledb everything works fine. respectively the connection string for oledb gonna change and this is my oledb connection string :

Provider=SQLOLEDB;Data
Source=myserverIP;Password=password;User
ID=sa;Initial Catalog=catalog

note: I've tried this also but no difference.


Hai, please set Connection Timeout attribute of your connection string .


Windows 2008 server strips out the password from the connection string.

You have to specifically assign the password to your connection 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
    }
}


Is TCP/IP an enabled connection protocol for the Sql-Server? You can check this with the Sql Server Configuration Manager under "Sql Server Network Configuration".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜