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'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:
\\.\pipe\mini-guid-here\tsql\query
e.g.,
\\.\pipe\7789925E-DCAA-4A\tsql\query
You should see the filename listed under databases.