I just took over a project that is using a VS Database project and I am hitting an early road block. There is a file localhost.publish.xml that I am assuming will build the local database (is that correct)? When I click Generate Script I am getting the error "Unable to connect to the target server" and everything I have read online talks about installing the Data Tools which I did and it isn't helping. It has been a few years since I have even opened Visual Studio so I know I am just missing the obvious, but I cant find documentation anywhere that is giving me a clue about what I am missing. I havent included any of the code because at this point I am not even sure what would be helpful to anyone.
Asked
Active
Viewed 1.3k times
2
-
The code is probably using a SQL Server Database. The database may of moved or you don't have the credentials to access the database. Check if the code has any SQL statements (SQLConnection, SQLDataAdapter, ...). The xml may contain the connections string or just creating a report output. – jdweng Dec 18 '15 at 14:08
-
what does the "generate script" actually do – esastincy Dec 18 '15 at 14:19
-
Why are you asking me??? It is your code. It probably a button which executes code in a form. When the project is not running use menu View : Solution Explorer. Find the form with the Generate Script button. Then press the Generate Script button which should take you to the code. – jdweng Dec 18 '15 at 15:41
-
Its not in the code. Im talking about when you double click the localhost.publish.xml file you get a window up with an option "Generate Script" and another option that says "Publish" – esastincy Dec 18 '15 at 15:43
-
They are setting in the project (a config file). I suspect you have an XAML file and the xml is an input into the XAML file. I would use the project menu Edit : Find. Change the setting to search entire Solution. Then search for 'SQL'. – jdweng Dec 18 '15 at 15:52
1 Answers
1
When you double-click localhost.publish.xml and it opens the Publish Database dialog, take a close look at the Target Database Connection. Make sure this is the database where you plan to run the SQL script and that this is a valid server you can connect to. Click the Edit button to change it. Your problem is either a) this is not a valid server, or b) you can't connect to this server from your computer (different network, firewall rules, etc).
The reason Visual Studio needs to connect to the database in order to generate the script is that it needs to determine if the script should contain CREATE or ALTER statements for your db objects based on whether or not they already exist.

Keith
- 20,636
- 11
- 84
- 125
-
Mine just has localhost, which I assumed was valid. This is an existing project that I am jumping into. Is having localhost there not valid? – esastincy Dec 18 '15 at 16:56
-
@esastincy localhost should be valid. Make sure you actually have a database instance running on your computer and that the credentials in the publish file are correct. Also check out [this](http://stackoverflow.com/questions/12774827/cant-connect-to-localhost-on-sql-server-express-2012) and [this](http://stackoverflow.com/questions/1339944/cant-connect-to-localhost-but-can-with-computer-name-in-sql-server-2008) to help troubleshoot the connection problem. – Keith Dec 18 '15 at 17:15