title: ASP SQL connection refused, necessary ports are open
body: <p>I'm trying to develop an ASP SQL connection to a MSSQL 2005 server. The SQL server is a sub server behind our main domain server, so a port forward has been setup from the WAN > LAN on port 1433 to allow the traffic to access the second server.</p>
  
  <p>I've done a telnet test on my end to see if the port forward is working correctly and it tells me the connection is refused. When I run the script I get the following result:</p>
  
  <blockquote>
    <p>Microsoft OLE DB Provider for SQL Server error '80004005'</p>
    
    <p>[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or
    access denied.</p>
  </blockquote>
  
  <p>The code is as follows:</p>
  
  <pre><code>&lt;%
  Dim cn
  Dim rs
  Dim SQL
  
  SQL = "SELECT count(*) FROM master"
  
  'create an instance of the ADO cn and rs objects
  Set cn = Server.CreateObject("adodb.connection")
  Set rs = Server.CreateObject("adodb.recordset")
  
  'open the cn to the database
  cn.Open "Provider=SQLOLEDB;Data Source=###.###.###.###,1433;Network Library=DBMSSOCN;Initial Catalog=blah;User ID=blah;Password=blah"
  'Open the rs object executing the SQL statement and return records
  rs.Open SQL,cn,adOpenKeyset,adLockOptimistic
  
  'first of all determine whether there are any records
  If rs.EOF Then
  Response.Write("No records returned.")
  Else
  'if there are records then loop through the fields
  Do While NOT rs.Eof   
  Response.write rs("count")
  Response.write "&lt;br&gt;"   
  rs.MoveNext    
  Loop
  End If
  
  'close the cn and rs objects to free up resources
  rs.Close
  Set rs=nothing
  cn.Close
  Set cn=nothing
  %&gt;
  </code></pre>
  
  <p>Thanks</p>