Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Failed to connect to server

Failed to connect to server

Scheduled Pinned Locked Moved Database
databasehelpcsharpsql-server
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alduin
    wrote on last edited by
    #1

    I had a hard time trying to decide whether I should post this in the database side of things or the vb.net. This is coming from a vb.net 3.5 application connecting to a SQL Server 2008 database. We currently have this application on 50 different SQL Servers though all of these other ones are SQL Server 2000/2005. This section of a code comes from a routine where we are validating that the database exists and makes sure that it is up to date. By this point we have already validated that the connection string (strADOConnString) is valid and that we can connect to the server. When we run this section of code where we check for the database name in the server the only difference between this and our normal connection string is that we are looking at the "master" database instead of our database. This section of code blows up with the "Failed to connect to server" error message. I've validated that the user does have the proper permissions on this server and this is further verified by our ErrHandler routine which writes the error to the database using the strADOConnString. I've tested this locally using SQL Server 2008 and have had no issues. They have tested this using the SA account leading me to suspect that it is not a simple permissions issue. I've made sure that they can logon to SQL Server Management Studio with this user with no pop ups and I've made sure that they can connect to the server through an ODBC with this particular SQL user. What else could be causing this error? Dim strADOConnStringMaster As String = strADOConnString strADOConnStringMaster = strADOConnStringMaster.ToString.Replace("Initial Catalog=" & objSystem.DatabaseName & ";", "Initial Catalog=master;") Try Dim connection As New SqlConnection(strADOConnStringMaster) server = New Server(New ServerConnection(connection)) bDbExists = server.Databases.Contains(objSystem.DatabaseName) connection.Close() Catch ex As Exception strStep = ".STEP01" Call ErrHandler(_moduleName & strStep, _className, String.Format("Server defined in database configuration does not exist. Message:{1}.", lDBVersion.ToString, Err.Description), Not bCmdLine) If Not bCmdLine Then MsgBox("Unable to locate server defined in database configuration.", MsgBoxStyle.Critical) End If Exit Sub End Try

    Some people sail through life on a bed of roses like a knife slicing through butter.

    L D 2 Replies Last reply
    0
    • A Alduin

      I had a hard time trying to decide whether I should post this in the database side of things or the vb.net. This is coming from a vb.net 3.5 application connecting to a SQL Server 2008 database. We currently have this application on 50 different SQL Servers though all of these other ones are SQL Server 2000/2005. This section of a code comes from a routine where we are validating that the database exists and makes sure that it is up to date. By this point we have already validated that the connection string (strADOConnString) is valid and that we can connect to the server. When we run this section of code where we check for the database name in the server the only difference between this and our normal connection string is that we are looking at the "master" database instead of our database. This section of code blows up with the "Failed to connect to server" error message. I've validated that the user does have the proper permissions on this server and this is further verified by our ErrHandler routine which writes the error to the database using the strADOConnString. I've tested this locally using SQL Server 2008 and have had no issues. They have tested this using the SA account leading me to suspect that it is not a simple permissions issue. I've made sure that they can logon to SQL Server Management Studio with this user with no pop ups and I've made sure that they can connect to the server through an ODBC with this particular SQL user. What else could be causing this error? Dim strADOConnStringMaster As String = strADOConnString strADOConnStringMaster = strADOConnStringMaster.ToString.Replace("Initial Catalog=" & objSystem.DatabaseName & ";", "Initial Catalog=master;") Try Dim connection As New SqlConnection(strADOConnStringMaster) server = New Server(New ServerConnection(connection)) bDbExists = server.Databases.Contains(objSystem.DatabaseName) connection.Close() Catch ex As Exception strStep = ".STEP01" Call ErrHandler(_moduleName & strStep, _className, String.Format("Server defined in database configuration does not exist. Message:{1}.", lDBVersion.ToString, Err.Description), Not bCmdLine) If Not bCmdLine Then MsgBox("Unable to locate server defined in database configuration.", MsgBoxStyle.Critical) End If Exit Sub End Try

      Some people sail through life on a bed of roses like a knife slicing through butter.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, 1. IMO this is the right forum to ask. 2. I'm no DB specialist at all, however I'll give you my ideas anyway. 3. I suspect the line

      strADOConnStringMaster = strADOConnStringMaster.ToString.Replace("Initial Catalog=" & objSystem.DatabaseName & ";", "Initial Catalog=master;")

      for a couple of reasons: a. I fail to see why ToString is used there b. if the search fails, strADOConnStringMaster remains unchanged and nothing gets signaled. This could be caused by a difference in white space, in casing, in any minor detail. So I'd suggest you clean up and code more defensively, if the replace has to happen, make sure it does, e.g. by storing the result in a different variable. 4. I'm not familiar with the Err object (I use C# most of the time), however I doubt Err.ToString() is as informative as Exception.ToString() is, so I suggest you show ex.ToString() in a MessageBox.Show when an exception gets caught. Hope this helps. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      1 Reply Last reply
      0
      • A Alduin

        I had a hard time trying to decide whether I should post this in the database side of things or the vb.net. This is coming from a vb.net 3.5 application connecting to a SQL Server 2008 database. We currently have this application on 50 different SQL Servers though all of these other ones are SQL Server 2000/2005. This section of a code comes from a routine where we are validating that the database exists and makes sure that it is up to date. By this point we have already validated that the connection string (strADOConnString) is valid and that we can connect to the server. When we run this section of code where we check for the database name in the server the only difference between this and our normal connection string is that we are looking at the "master" database instead of our database. This section of code blows up with the "Failed to connect to server" error message. I've validated that the user does have the proper permissions on this server and this is further verified by our ErrHandler routine which writes the error to the database using the strADOConnString. I've tested this locally using SQL Server 2008 and have had no issues. They have tested this using the SA account leading me to suspect that it is not a simple permissions issue. I've made sure that they can logon to SQL Server Management Studio with this user with no pop ups and I've made sure that they can connect to the server through an ODBC with this particular SQL user. What else could be causing this error? Dim strADOConnStringMaster As String = strADOConnString strADOConnStringMaster = strADOConnStringMaster.ToString.Replace("Initial Catalog=" & objSystem.DatabaseName & ";", "Initial Catalog=master;") Try Dim connection As New SqlConnection(strADOConnStringMaster) server = New Server(New ServerConnection(connection)) bDbExists = server.Databases.Contains(objSystem.DatabaseName) connection.Close() Catch ex As Exception strStep = ".STEP01" Call ErrHandler(_moduleName & strStep, _className, String.Format("Server defined in database configuration does not exist. Message:{1}.", lDBVersion.ToString, Err.Description), Not bCmdLine) If Not bCmdLine Then MsgBox("Unable to locate server defined in database configuration.", MsgBoxStyle.Critical) End If Exit Sub End Try

        Some people sail through life on a bed of roses like a knife slicing through butter.

        D Offline
        D Offline
        David Mujica
        wrote on last edited by
        #3

        Without changing your connection string, you should be able execute this SQL statement: SELECT name FROM master..sysdatabases You could then determine whether or not your database is installed on that server. This of course will only work if the user you are connecting with has the proper permissions to access the master tables. Give it a shot. :thumbsup:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups