sQL: export database to asp.net - asp.net

I am trying to export my database on sql server 2008 as a SQL server primary data file so that I can drag and drop it within my ASP.NET application APP_Data Folder, rather than refering the web app to the database datasource in sql server 2008. This might generate a problem in accessing the database when the web app is hosted. Is there a way to export it as .mdf file with its logs, drag and drop it to my web app ?
Regards.

M. Shbib, I think what Mr. Lewis means is "have you tried detaching the database in SQL Server, then copying the .mdf and .ldf files from the SQL Server Data folder to your App_Data folder?"
You can find where your files are by right-clicking your database in SQL Server and selecting Properties. The path is listed in the File section, but you may have to scroll right to find it. It should be something like c:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLSERVEREXPRESS\MSSQL\DATA (depending on your version of SQL Server). You will need to detach the database in SQL Server before you are allowed to copy it, otherwise you'll get an error that it is in use. Once you've detached it, navigate to the Data folder, copy both the mdf and ldf files and paste them into your App_Data folder.

Have you tried detaching the database on the SQL server, then copying the file to your App_Data folder?

Related

SQL Server Database Losing Primary Key after importing to ASP.NET Project

I am building a Website using ASP.NET MVC 4.5.
I am trying to import a database (oringal in .mdb) into the project.
What I did is:
In SQL Server Management Studio, create a new database and import the data from the mdb file.
Detach the database.
Copy mdf and ldf files to the desktop (Unable to add into App_Data when these files are in "Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA" even if I close SSMS and kill the "sqlservr.exe" process (it just keeps reopening).
Using "Add->Existing Item..." to add the mdf file into App_Data folders.
When I check with the server explorer and open the table definition, all the primary keys are gone.

Exporting ASPNETDB.MDF to an external database

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

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.

How to include database schema and data in setup and deployment of asp.net web application?

I am trying to deploy my web application created with asp.net in visual studio 2010. I have successfully created .exe and .msi file, install it and run using IIS Manager. However, it needs a database which is why it is returning
System.Data.SqlClient.SqlException: The SELECT permission was denied on the object 'TableName', database 'master', schema 'dbo'.
whenerver I try to run it on browser with localhost.
How do I include my database file in deployment so that when I install my application in another computer, the database will also be created?
It is not at all clear what exactly you mean by database file but if you are referring to an SQLLite or SQL Server CE database file all you have to do is go to properties and change the "Copy to Output Directory" property to "Copy if Newer" (don't forget to do the same with the required class libraries).
If you are referring to SQL Server, Oracle or some other RDBMS database than you can't just copy the file, you'd have to either use DDL to create the database or attach the database file using the SSMS.
EDIT: I did not pay attention to the exception you posted so the second part of my question is relevant. SQL Server database file cannot be just copied to another computer, the target computer must have the SQL Server installed and you must detach the file from your local SQL Server and attach it on the remote SQL Server using the SQL Server Management Studio.

How do I copy a DB from the server to the application's AppData folder?

I've been working on an ASP.NET application accessing a DB in my local machine.
Now I want to have this DB in the app's AppData folder instead, so I can easily work on it from within VS SQL instance accessing the mdf file, and easily copy and share it between programmers.
Thanks a lot!
First, use SSMS to detach your database.
Next, find the MDF and LDF files for your database. They should be in:
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
Copy those files to your App_Data folder.
If you want to switch to using SQL Express, then change your connection string to point to the MDF file. If you want to continue using SQL Developer / etc, then use SSMS to re-attach the MDF and LDF from their new location.
I guess I should add that this usually isn't a good idea, but I assume you have your reasons.

Resources