Nannette Thacker ShiningStar.net

ASP.net Web Application Development

Sponsors

News

See all Blog Posts by Nannette.

Nannette Thacker, consultant and owner of Shining Star Services LLC, specializes in development of custom dynamic database driven web applications utilizing ASP.net technologies. Nannette has been developing ASP sites since 1997. Nannette has written numerous articles on web development techniques and tutorials.

Nannette is the owner and developer of ChristianSinglesDating.com.

 Subscribe in a reader




Deploying the ASPNETDB.MDF to a Remote SQL Server Database

Topic: Using Publish to Provider to generate scripts to create/move/copy .MDF databases to your remote SQL Server database.

When using Visual Studio to create your web projects, you may choose to use the ASP.NET Configuration tool to create your users and roles. This will create a set of tables which are then placed in a local ASPNETDB.MDF SQL Server express database. (These same steps may be used to copy any MDF database to your remote SQL Server database.)

Once you've done everything you need to do locally and you're ready to deploy this to your production database server, how do you do that?

Here's what I did. Maybe there's a slicker, quicker way. But this is free and fairly simple to me.

In this example, I am using Visual Studio 2008 and deploying to a SQL Server 2008 Web Edition database.

From Visual Studio, in your Server Explorer tab, you'll notice all of the tables created by default. As well, there are Views, Stored Procedures, etc.

First, we want to create a SQL script to recreate all of those objects. So right click the database and select Publish To Provider:

This will bring up the Database Publishing Wizard. Select the button to continue.

You will be presented with a list of your databases and asked to select your database. There is a checkbox to Script all objects in the database. Select it. Select Next to continue.

Now you are given the option to script to a file. It presents a default path, I changed mine.

In the next window you will be offered several options. In my case, I needed to change the target database to SQL Server 2008. Select the target you need, then Select to continue. As per Chris Rivera's comment below this blog, if 2008 doesn't show as an option, make sure you download and install SP1. See my post on installing SP1.

Next you may review the options selected.

Click Finish to complete the Wizard. You'll see the progress.

Now you have a fancy script generated for you. This script will select, alter, drop, update, insert, etc. etc., all needed values.

Now to get this to your database server. Mine happens to be on the same network as my webserver, but not on the same network as my development box, so I created a folder within my project and placed the script in there. When I updated my project, this sql script was then copied to my web server. From my database server, I then copied it via the network to my SQL Server 2008 Web Edition desktop.

I opened my Microsoft SQL Server Management Studio and created my new blank database. Just right click Databases, and select New Database. Give it a name and select OK.

Then with this new database selected, click the sql file on your desktop and it will open up in your screen. Again, with the new database selected, right click in the script and select "Execute." This will execute the script on the selected database and create all the objects needed.

Voila! You are done! You now have a full-blown SQL Server 2008 database on your production server!

Now, assuming you have created other MDF's for other projects that have nothing to do with the database created by Microsoft, you may use this same method to create your scripts. Also, this same functionality is in Visual Web Developer Express Edition.

May your dreams be in ASP.net!

Nannette

 

 

Comments

seed said:

sounds great except I keep getting a timeout error when it gets to step 3.

# November 4, 2008 1:57 PM

Chris Rivera said:

Excellent Post!  It made me realize that I had to download the Microsoft Visual Studio 2008 Service Pack 1 so I could publish to SQL Server 2008 which gave me Data Publisher 1.3.  Before I installed this I didn't have SQL Server 2008 as an option for "script for target database."

# November 26, 2008 1:45 AM

Community Blogs said:

In SQL Server, if you wish to copy the structure of an entire database, including the Constraints, Keys

# December 1, 2008 12:25 PM

Chris Rivera said:

Be careful that your project path doesn't have too many characters when you use this utility!!  I got an error that wouldn't let me past the "Select Database" screen and got an error that says "There are no objects in database ..."

After reading the post below I moved my project to my C: drive and the error went away.

www.codeplex.com/.../View.aspx

-Chris

# December 1, 2008 1:54 PM

Bolsa de trabajo said:

great help thanks.

# December 26, 2008 11:07 PM

adebayo said:

this is wonder, it absolutely solved my problem. plz keep up the good work.

# January 22, 2009 9:38 AM

Tom said:

After trying this procedure everything worked to a "T" until I got the "Select the new database and chick on the Script File and click execute! It executes and completes OK, but I hav eno idea where it ended up putting the tables it should have generated. The ASPNETDB still is a skeleton database with no tables from the \sqlexpress AspnetDB on the development system. ????

# January 22, 2009 10:40 AM

nannette said:

Tom,

Did you forget to create your new blank database first?

From blog:

I opened my Microsoft SQL Server Management Studio and created my new blank database. Just right click Databases, and select New Database. Give it a name and select OK.

Then with this new database selected, click the sql file on your desktop and it will open up in your screen. Again, with the new database selected, right click in the script and select "Execute." This will execute the script on the selected database and create all the objects needed.

# January 22, 2009 11:57 AM

nannette said:

Tom,

On your development system, the place you want the database to be...

you need to copy the script to there...

create your blank database...

and execute the script there...

Nannette

# January 22, 2009 11:59 AM

Tom said:

Your instructions in the last paragraph was misleading. Here's what I did to get it to work.

Double click on the .sql script file you created. This brings up the SQL Management Server asking for a DB Connection. Respond with your SQL Server. The script file then appears in the right panel, left panel is blank. On the Toolbar, select where the drop down listbox appeaars, your blank database you created earlier. Then right click on the script in the right panel and select "Execute". It works fine, the instructions at the end just confused me. It doesn't work if you start the SQL Management Server first and go through the steps. Thanks, for the most part this was a very helpful piece of information!

# January 22, 2009 12:33 PM

nannette said:

Tom,

Are you executing your script locally? And not on a remote sql server database? It sounds like that's the difference.

If so, that info is definitely good to know too! thanks!

Nannette

# January 22, 2009 1:09 PM

bikeman said:

quote

"Also, this same functionality is in Visual Web Developer Express Edition."

Not in VWD 2008 it isn't!

# May 19, 2009 9:29 AM

How to back up a visual studio 2008 database « Naked Science Com Quiz said:

Pingback from  How to back up a visual studio 2008 database « Naked Science Com Quiz

# June 10, 2009 1:57 PM

pcook said:

Thank you for providing this info. Your instructions were very helpful. I published the ASPNETDB.mdf database to my remote server but I am still having issues trying to login into my site. I have some pages that requires a user to login in order to view. I created the user's, roles and memberships using ASP.NET Configuration utility in VS 2005. I precompiled the site in VS 2005. Everything works fine locally but when I try to login to the published website I get an error 26 something about an instance not being found. Is there something I am missing. Do I need to setup some type of setting in the webconfig file?

# June 22, 2009 10:48 AM

ddecremer said:

Given that my databases are held on a shared server, I cannot have one of them named ASPNETDB.MDF.  So, I have to use a different name for it.  Let's say that I named it myaspnetdb.mdf.  When going from local to remote server by the steps above, does it recognize that the original db name is different from the target and adjust accordingly?  The above steps in this article worked fine for me, however, my log-ins still only work locally, not on my remote server.  Are the login controls still looking for a db named ASPNETDB.MDF and not my renamed one?  How can I get it to point to the renamed one?  Thanks!

# October 22, 2009 4:47 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)