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. General Programming
  3. C#
  4. How to resolve network related or instance specific error

How to resolve network related or instance specific error

Scheduled Pinned Locked Moved C#
databasesysadminsql-serverhelptutorial
7 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.
  • U Offline
    U Offline
    User 11968669
    wrote on last edited by
    #1

    public void GetBackup(string strDBName) { if (string.IsNullOrEmpty(strDBName)) { MessageBox.Show("Server Name & Database can not be Blank"); return; } else { string destinationPath = ConfigurationManager.AppSettings.Get("BackupDestinationPath"); BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File); ServerConnection connection = new ServerConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString); Server sqlServer = new Server(connection); Database db = sqlServer.Databases[strDBName]; The above line Database db = sqlServer.Databases[strDBName]; is causing the below mentioned error. 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"} Message : Failed to connect to server D>ata Source=PC210090\\SQLEXPRESS;Initial Catalog=testdb2;Persist Secur>ity Info=True;User ID=sa;password=password-1"}

    OriginalGriffO N 3 Replies Last reply
    0
    • U User 11968669

      public void GetBackup(string strDBName) { if (string.IsNullOrEmpty(strDBName)) { MessageBox.Show("Server Name & Database can not be Blank"); return; } else { string destinationPath = ConfigurationManager.AppSettings.Get("BackupDestinationPath"); BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File); ServerConnection connection = new ServerConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString); Server sqlServer = new Server(connection); Database db = sqlServer.Databases[strDBName]; The above line Database db = sqlServer.Databases[strDBName]; is causing the below mentioned error. 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"} Message : Failed to connect to server D>ata Source=PC210090\\SQLEXPRESS;Initial Catalog=testdb2;Persist Secur>ity Info=True;User ID=sa;password=password-1"}

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      The error message is pretty explicit, and even tells you what to do.

      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.

      So look at your connection string, and make sure that it is correct, and that the computer you are running your application on can "see" the "PC210090" PC on it's local network segment. Then check the user name and password combination is also correct. And don't use the SA user login - it has complete access to the databases, you should be using a user with specific permissions at all times.

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • U User 11968669

        public void GetBackup(string strDBName) { if (string.IsNullOrEmpty(strDBName)) { MessageBox.Show("Server Name & Database can not be Blank"); return; } else { string destinationPath = ConfigurationManager.AppSettings.Get("BackupDestinationPath"); BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File); ServerConnection connection = new ServerConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString); Server sqlServer = new Server(connection); Database db = sqlServer.Databases[strDBName]; The above line Database db = sqlServer.Databases[strDBName]; is causing the below mentioned error. 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"} Message : Failed to connect to server D>ata Source=PC210090\\SQLEXPRESS;Initial Catalog=testdb2;Persist Secur>ity Info=True;User ID=sa;password=password-1"}

        N Offline
        N Offline
        NeillJam
        wrote on last edited by
        #3

        Yeah, the error is pretty self explanatory,a nd OriginalGriff is right, don't use sa account. That being said; Did posting the code mess up your connection string or is that whats wrong? Also why are there 2 \'s between hostname and instance name? Message: Failed to connect to server D**>ata Source=PC210090\\SQLEXPRESS;Initial Catalog=testdb2;Persist Secur>**ity Info=True;User ID=sa;password=password-1 Neill

        U 2 Replies Last reply
        0
        • N NeillJam

          Yeah, the error is pretty self explanatory,a nd OriginalGriff is right, don't use sa account. That being said; Did posting the code mess up your connection string or is that whats wrong? Also why are there 2 \'s between hostname and instance name? Message: Failed to connect to server D**>ata Source=PC210090\\SQLEXPRESS;Initial Catalog=testdb2;Persist Secur>**ity Info=True;User ID=sa;password=password-1 Neill

          U Offline
          U Offline
          User 11968669
          wrote on last edited by
          #4

          This is my connection string.

          1 Reply Last reply
          0
          • N NeillJam

            Yeah, the error is pretty self explanatory,a nd OriginalGriff is right, don't use sa account. That being said; Did posting the code mess up your connection string or is that whats wrong? Also why are there 2 \'s between hostname and instance name? Message: Failed to connect to server D**>ata Source=PC210090\\SQLEXPRESS;Initial Catalog=testdb2;Persist Secur>**ity Info=True;User ID=sa;password=password-1 Neill

            U Offline
            U Offline
            User 11968669
            wrote on last edited by
            #5

            My Connection string :

            N 1 Reply Last reply
            0
            • U User 11968669

              My Connection string :

              N Offline
              N Offline
              NeillJam
              wrote on last edited by
              #6

              Well the connection string format looks fine. There could still be quite a few things causing the problem. 1. Are your sure the PC210090 name is correct? 2. Is SQLEXPRESS correct or are you using a named instance? 3. Is the DB name correct? 4. Is the username correct? 5. is the password correct? If you have SQL Management Studio installed on your machine, can you connect to the database from there using the username and password? In Visual Studio, try creating a connection from the Server Explorer window. Is PC210090 where the db server is located the same machine you are using? It could be a firewall issue. There are really quite a few reasons as to why its could not be working. Neill

              1 Reply Last reply
              0
              • U User 11968669

                public void GetBackup(string strDBName) { if (string.IsNullOrEmpty(strDBName)) { MessageBox.Show("Server Name & Database can not be Blank"); return; } else { string destinationPath = ConfigurationManager.AppSettings.Get("BackupDestinationPath"); BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File); ServerConnection connection = new ServerConnection(ConfigurationManager.ConnectionStrings["CostAllocationEntities2"].ConnectionString); Server sqlServer = new Server(connection); Database db = sqlServer.Databases[strDBName]; The above line Database db = sqlServer.Databases[strDBName]; is causing the below mentioned error. 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"} Message : Failed to connect to server D>ata Source=PC210090\\SQLEXPRESS;Initial Catalog=testdb2;Persist Secur>ity Info=True;User ID=sa;password=password-1"}

                N Offline
                N Offline
                NeillJam
                wrote on last edited by
                #7

                Another thing that I am confused by (which happens far too easily.) is if you are using a specific framework? Why create ServerConnection with the specified ConnectionString which specifies the initial database, and then attempt sqlServer.Databases[strDBName] which is the database name passed into the method? Neill

                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