How to resolve network related or instance specific error
-
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"}
-
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"}
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...
-
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"}
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
-
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
This is my connection string.
-
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
My Connection string :
-
My Connection string :
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
-
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"}
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