Showing posts with label mdf. Show all posts
Showing posts with label mdf. Show all posts

Wednesday, March 7, 2012

Creating a DB script

Somebody knows a tool able to generate DB scripts from a .mdf file?

Management Studio Express.

Right-click on the database and choose 'Script Database As..." and select an option. You can also script individual objects. This does not include data, you'd need to use BCP for data.

Management Studio Express CTP is at http://www.microsoft.com/downloads/details.aspx?familyid=57856cdd-da9b-4ad0-9a8a-f193ae8410ad&displaylang=en.

Regards,

Mike Wachal
SQL Express team

-
Check out my tips for getting your answer faster and how to ask a good question: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=307712&SiteID=1

|||I already tried Managment Studio Express, but for some reason it cannot access my .mdf file that is located at:
C:\Documents and Settings\Neto\Mis documentos\Visual Studio 2005\Projects\ProjectName\Database\myBD.mdf

The tree view that browses the folders won't let me get past 'My Documents'|||

SQL Express runs as the Network Services account, which is a limited access account that doesn't have permissions for a number of things, including User Profile directories.

If this is a one time operation, I would suggest detaching the database and moving it to a location where you can access it (such as the MSSQL\Data directory), attaching it there and then using Management Studio to generate the scripts.

If this is a task you need to do repeatedly, you'll probably need a programatic way to do this. I haven't been able to find a T-SQL method for doing this, maybe someone else knows of one. If not, you can do this from SMO, which you can get an overview of starting at http://msdn2.microsoft.com/en-us/library/ms162557.aspx.

Regards,

Mike Wachal
SQL Express team

-
Check out my tips for getting your answer faster and how to ask a good question: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=307712&SiteID=1

Saturday, February 25, 2012

Creating a database from script - permissions problems

We deploy our app via ClickOnce. Rather than shipping the .mdf and .ldf, the app detects whether the database is there and creates it via script if it's not. The script was originally generated from SQL Exrpess Mangement Console, etc.

In the past, we've made the stipulation that the user must have administrator access to the machine. However, we now need to find a workable solution for users who are not administrators on their machine. Currently, we use the following connection string before attempting to run the db creation script:

conn.ConnectionString = "Server=.\\sqlexpress;Integrated Security = true;User Instance=false";

The script fails when trying to execute "CREATE DATABASE [myDatabaseName] ON PRIMARY "

with the error:

"CREATE DATABASE permission denied in database 'Master'"

How can we get around this permissions issue in the most automated way possible?

TIA!

Hi,

you will need to have a user with dbcreator permissions, otherwise you won′t be able to make an entry in the sysdatabases (Creating a database). Can you use any administrative SQL Server login to connect to the database and make this possible ? The connection string has to include the userid as well as the password then.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de