I’m cloning a local C#-SQL Windows Forms application to a new laptop. I’ve successfully cloned the C# project and back-up-and-restored the SQL database to the new machine, but the new project is unable to read/query any data from the new, cloned SQL database.
Since the SQL DB is local, the LINQ-to-SQL addressing is slightly different on account of the computer having a different name. So, I deleted the SQL table representations from the existing LINQ .dbml’s graphical interface, removed the old server connection from the Server Explorer, added the new server connection, and click-and-dragged the table objects from the Server Explorer’s new Data Connection object to the now-empty .dbml file.
Upon rebuilding and running the application in debug mode, I found that the dropdown menus which pull from the SQL DB are empty. Upon trying a button function which pulls from the database, I get the following error:
SqlException was unhandled
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)
(The cloned SQL server is configured to allow remote connections, TCP/IP is enabled in SQL, and the original C#-SQL application works without a hitch.)
Check in your
Web.Configand make sure that your Connection String is set up correctly. Also check to make sure that when you initialize yourDataContextthat you are using the correct Connection string from your Web.Config.Sometimes when you remove dbs from the dbml, it doesn’t completely clear the web.config of the old entries. Look for a line like this in your designer.cs file:
Compare it with the connectionStrings in your web.config