Exporting ASPNETDB.MDF to an external database - asp.net

ASP.Net 4.0/C#/MSSQL/Microsoft SQL Server Management Studio
Hey I am now at the stage where I want to move a project to a live server
Now I want to move the tables from the ASPNETDB file in the App_Data folder
to the server.
I have used the Aspnet_regsql.exe tool to successfully generate the following tables
on my shared hosted server
dbo.aspnet_Applications
dbo.aspnet_Membership
dbo.aspnet_Paths
dbo.aspnet_PersonalizationAllUsers
dbo.aspnet_PersonalizationPerUser
dbo.aspnet_Profile
dbo.aspnet_Roles
dbo.aspnet_SchemaVersions
dbo.aspnet_Users
dbo.aspnet_UsersInRoles
dbo.aspnet_WebEvent_Events
Now what is the next step to essentially copy the tables from ASPNETDB.MDF
to these tables on the server?
Many thanks =)

What version of SQL server have you got?
If you can open the database locally in SQL Management Studio you can just use Generate Scripts that you can then simply open and run on your production server. It has the option to copy
Data
Schema
Both
So you can start with an empty database on Production and copy both the data and schema at once with a single .sql file and you'll be good to go.

You can use the export data feature from the management studio to migrate the data from the msf file to the live dtabse.

You are really better off putting all the membership etc. tables, views and stored procs into the main database for your production application. You can do this with the Database Publishing Wizard, which will create a script to recreate everything including all the data. No need to use two separate databases.

Alternatively, one can run this exe to copy empty tables from ASPNETDB.mdf to external SQL server.
drive:\WINDOWS\Microsoft.NET\Framework\versionNumber\aspnet_regsql.exe

Related

Publish ASP.NET project with local data on Azure

I'm quite new to ASP.NET and I encountered a problem when publishing my project to Azure. After configuring the connectionStrings in Web.config, I have successfully uploaded my local database structure to Azure. However, all tables on Azure are now empty, without any local data. So how can I upload both the database structure as well as the data in it? Thanks in advance.
To migrate an existing SQL Server database to Azure SQL Database you can export the schema as a TSQL script and then execute that script against Microsoft Azure SQL Database as follows:
1.Open SQL Server Management Studio and connect to an instance of the Database Engine.
In Object Explorer, right click a database to open a menu, select Tasks…, and then select Generate Scripts.
2.Choose objects to export.
3.Set scripting options. You have the options to save the script to file, clipboard, new query window; or publish it to a web service.
4.Set advanced scripting options.
You can also set the Types of data to script to one of the following based on your requirements: Schema only, Data only, Schema and data.
5.After the script is created, you have the option to modify the script before running the script against an Azure SQL Database to transfer the database.
You can now run this script on your Azure SQL Database.
For more details, you could refer to this article.
You have to create a post deployment script. If the tables are created just fine on your azure application, then you must define what default data they will have. So in your post deployment script you will insert the data you want.

sql query or command tool to append mdf file to windows azure SQL DB

I'm trying to migrate my ASP.NET MVC app to Windows Azure, but on my code I have a module that imports data from a ".mdf" file hosted on the server to my SQL-Server DB using the SQL-Server "sp_attach_db" and "sp_dettach_db" commands and then referencing tables with {databasename}.{owner}.{table}, now with Azure it is not possible to do it this way but I can't figure out a workaround, any idea?
Thank you
Added: Conclusion
It seems not possible to attach "on the fly" a DB to SQL azure and share data with the others databases

How to extract the database file when using SQLExpress in Visual Studio

I have made my database in SQLExpress and its a master database . I would like to create a CD for my project so need the database file. I am not able to find that file please suggest a solution
thanks!
Your database files would be in the App_Data folder by default if you are using SQL-Express provided with Visual Studio.
You can generate an SQL script of your database which can be used to re-create it in different db server by running the script again. For this right-click on the database in the Server Explorer and select Publish to Provider.
You'll need the .mdf and .ldf in the SQL Server installation directory, but if you've created everything in the master database, I'd recommend creating a different database and moving everything there instead. The master db shouldn't be used for stuff like that.

Where to start when uploading a SQL Server database to a web server

Here's another question on my lips.
My website uses a database which was created in SQL Server 2008 R2 Enterprise Edition. Where do I start when I plan to upload the database to the web server? My Website will require this database. Should I send the Scripts which created the database to the Staff of the web server so they can Recreate my database, or should I detach my database and place it in the App Data folder, followed by an update of my Connection strings to reference the detached database?
Another thing I fear is the Database version. Will my Database connection break on the web server because of the "Version of database is 655 and cannot be downgraded to 612" Error? and If yes, How would I prevent that?
The Best way would be to
1: Send them the scripts, let them run it on their side, they should then be able to provide you with server name, database name user id etc.
2: Create a .bak backup file of the database and send that to them and ask them to restore it for you, this way you save a lot of the hassle of creating scripts and you also ensure that the database is like you want it and you know they haven't made a mess of restoring the scripts.
You can also ask them if they don't have some sort of management console where you can upload the database yourself
My suggestion would be to create a back up of the SQL database, and give that to the web server admin to restore on their server. This will mean that you can guarantee that you will get no problems with the structure, and you should simply have to change the connection string in your Web.Config (assuming that you have always created your connections in code based on the connection string in the web.config), to contain a user name and password that your web server admin gives you (if it's a back up and restore of your db, assuming you use SQL authentication, the new db on the web server will have the same users anyway).
Some options;
If you have access via Management Studio just use the import/export tools or the Copy Database Wizard
If the remote sql server can read from one of the site directories you have access to upload a .bak backup and restore, or upload the database files proper and use one of the sp_attach* procedures
Script the database (including data) upload the individual files & create a quick and dirty script that will execute them.

How do I migrate a SQL MDF File to a production SQL Server? (ASP.NET)

I have an ASP.NET project that also uses a SQL MDF File. My target server is SQL 2008R2 or SQL Azure.
I would like to know what deployment options I have as I migrate from DEV to PROD. In case it matters I'm not under any regulation to maintain PII or similarly private data.
How do I move my test schema and perhaps data to production?
You can move the entire database, including the data by attaching the MDF file to the new SQL server. Otherwise you can select all objects and generate CREATE scripts to copy the schema over.
Yes, you can attach to the MDF file directly, or do a backup / restore to get it over to SQL Server 2008.
I haven't played with SQL Azure... From what little I've heard I think you might be stuck scripting the data as durilai suggested (last I heard we're not allowed to do backups / restores for SQL Azure).
In SQL Server Management tools, right click on the database and click 'Script Database As' to create an SQL script for your database. You can also do something similar at the table level if you want the data.

Resources