How to – Replace aspnetdb.mdf with an SQL Database

So you have created an ASP.NET website using the template in Visual Studio. Now you want to deploy your site and instead of using an .mdf file, you want to use a database on SQL Server.

Here are the things you need to achieve in order to do that.

1- Create an empty database on your SQL Server
2- Register your database usingĀ ASP.NET SQL Server Registration Tool (Aspnet_regsql.exe)
(check my post on how to do it.)
3- Update the web.config of your website. (update Connection String)

Sample default Connection String:
connectionString=”data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true”

How it should be:
connectionString=”Data Source=DBSERVERNAME;Initial Catalog=YOURNEWDBNAME;Integrated Security=True”

4- Add NT AUTHORITYNetwork Service to the users of your DB (YOURNEWDBNAME) as “db owner” (check my post on how to do it)

Now your website should be working on your new database.

Hope this helps someone.

Good luck,

Leave a Reply

Your email address will not be published. Required fields are marked *

Warning: mysqli_num_fields() expects parameter 1 to be mysqli_result, boolean given in /home/biginf5/public_html/wp-includes/wp-db.php on line 3215