SQL Server does not allow remote connections

  • I wrote a website using ASP .NET (to be accessed by anybody over the internet).

    There is one page on the website that is pulling a list of products from a table stored on SQL Server 2005 using a sqldatareader.

    The application was published on the client's webserver and their database is on their sql server.

    I am using the following connection string to connect to sql:

    "server=ip.address.here;database=dbnamehere;trusted_connection=false;uid=myuserID;password=myPassword; Connect Timeout=360; Max Pool Size=1000; Enlist=False; Pooling=True; "

    I upload the application on three different servers (same code, same DB) and it works perfectly. However, when I publish it on their server it doesn't work. Instead, it is giving me the following error:

    "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) "

    We have search a lot and even followed all the steps on this link with no luck: http://littletalk.wordpress.com/2008/03/21/an-error-has-occurred-while-establishing-a-connection-to-the-server-when-connecting-to-sql-server-2005-this-failure-may-be-caused-by-the-fact-that-under-the-default-settings-sql-server-does-not-all/

    We compared settings with other servers and can't find anything different.

    Can somebody help me with this? I greatly appreciate it..

    Just in case, the code in my app looks like this (I have done this million of times but it doesn't mean I can be doing something wrong and just not notice it):

    ----------------------------------------

    Dim strConn As String = "server=ip.address.here;database=dbnamehere;trusted_connection=false;uid=myuserID;password=myPassword; Connect Timeout=360; Max Pool Size=1000; Enlist=False; Pooling=True; "

    Dim objConnect As SqlConnection = New SqlConnection(strConn)

    Dim objDataReader As SqlDataReader

    Dim strMenus As String

    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    Response.BufferOutput = True

    If Not Page.IsPostBack Then

    'Call list of products from database

    getproducts()

    End If

    End Sub

    'getProducts subroutine

    Sub getproducts()

    strMenus = " "

    'Call a function to create the sqlDatareader

    objDataReader = getReader("Select * from productCategories order by categoryName ")

    If objDataReader.HasRows Then

    While objDataReader.Read

    strMenus = strMenus & " "

    End While

    End If

    objDataReader.Close()

    strMenus = strMenus & " "

    lblProducts.text = strMenus

    End Sub

    'getReader Function.

    Function getReader(ByVal strQry As String) As SqlDataReader

    objConnect.Open()

    Dim objCommand As SqlCommand = New SqlCommand(strQry, objConnect)

    Dim dR As SqlDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)

    Return dR

    End Function

    --------------------

  • LISETH_T (7/15/2008)


    I upload the application on three different servers (same code, same DB) and it works perfectly. However, when I publish it on their server it doesn't work. Instead, it is giving me the following error:

    do you publish the database to a new db server as well or is the database still on the same server

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • Right now the DB is in the new sql server (the one connected to the web server).

  • That error's the generic 'I can't connect' error. It could be because the server doesn't allow remote connections. It could be that the service is stopped, or there could be a firewall or something preventing connections.

    Can you connect via a querying tool, like Management Studio Express?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • LISETH_T (7/15/2008)


    'Call a function to create the sqlDatareader

    objDataReader = getReader("Select * from productCategories order by categoryName ")

    Unrelated comment: Are you familiar with SQL injection? This piece isn't vulnerable, but the embedded SQL suggests that other places might be.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Issue Fixed (I was provided with the external IP address instead of the internal. Once the IP address was changed the connection worked).

    Are you familiar with SQL injection? This piece isn't vulnerable, but the embedded SQL suggests that other places might be

    I understand that I should used parameters to avoid that the end user passes values or characters into my sql statement to manipulate my database. As you said, in this case I am not vulnerable but if there is any recommendation for me I would appreciate it and thanks in advance.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply