Running sql scripts against an attached database?
I've got an MDF attached to an instance of Sql Server 2008 Express, and I need to run some sql scripts against it to generate tables, indexes, etc.
But I can't figure out how to get this to work. If I load the scripts in Visual Studio, it only allows me to connect to the server and run it against a database. I can't choose a different provider (Microsoft Sql Server Database File), so I can't select my MDF.
This leaves me the only option of running the script as individual queries, but that won't work as it appears it doesn't support TSQL CREATE statements.
How can I run my sql script against an attached database?
I ran into this same problem and here is what worked for me.
Right-click on the script and choose Connection > Connect
The server name and authentication should already be set for the local SQLEXPRESS instance.
Click the Options button
Click the Additional Connection Parameters tab
Paste in the the path to your database file using the following as a guide:
Click the Connect button
If you still have trouble connecting it may be because there is already an open connection. Check Server Explorer and if connection is open, Right-click and choose Close Connection.
This process will also create a persistent connection as long as the SQL Script remains connected. You will want to close the script or choose Right-click > Connection > Disconnect.
More information can be found at this question: EF4 Generate Database
I'm assuming you mean you have an local MDF file in Visual Studio (like an App_Data folder)?
You can use SQL Management Studio by connecting with the named pipe.
First, open up a new query in Visual Studio on the attached DB using their anoying query tool. In the properties window, under ServerName, save that mini guid thats in the format of "your-PC-name\mini-guid". Connect using Management Studio like this:
You should see the filename listed under databases.