1 Replies - 413 Views - Last Post: 13 October 2011 - 01:44 PM Rate Topic: -----

#1 sethwhite42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-September 10

Can't Connect to Sql server with code but can thru Datasource Desi

Posted 13 October 2011 - 12:17 PM

When I use the Visual Studio 2010 Datasource designer to connect to my SQL server remotely everything works fine. However, if I try to connect programatically from the same project and machine using this code (sensitive info X'd out):
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=\"XX.XXX.XXX.XXX, 1433\";User ID=ASPNET;Password=XXXXXXXX";
            conn.Open();


I get the following error:

{"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The requested service provider could not be loaded or initialized.)"}

port 1433 is open on the remote network and like I said I can browse the server fine through the datasource designer. I'm using the same connection string as the designer in my code and have tried several different ways of writing it.

Is This A Good Question/Topic? 0
  • +

Replies To: Can't Connect to Sql server with code but can thru Datasource Desi

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Can't Connect to Sql server with code but can thru Datasource Desi

Posted 13 October 2011 - 01:44 PM

go to SQL Server Configuration Manager(Start->Programs->Microsoft SQL Server 200X->Configuration Tools) and under SQL Server Network Configuration -> Protocols for <Instance_Name>( If you have a default installation <Instance_name> = MSSQLSERVER). Make sure that TCP/IP is not disabled. Same thing for SQL Native Client XXX Configuration(XXX is the version : 9.0 or 10.0).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1