How to solve problem to add Sql Server2008R2(.mdf) in Visual studio 2010

Hi friends! There are some persons who are  faced problem, when they add database(.mdf) on Asp.Net website in visual studio 2010. I have also faced this type of problem .
When you add database(.mdf) on Asp.Net website in visual studio 2010 and following error occurs which is shown below,then you can solve this problem easily.
see it:

  There are some steps to solve this error and add (.mdf) database on Asp.Net website.
Step 1- First open your visual studio->New->Website->Asp.Net Empty Website->ok.

Step 2- Now go Tools-->Options-->Database Tools->click Data connection-->Now remove Sql Server Instance Name from Right hand box -->click ok.
see it:


Step 3- Now  open solution Explorer-->Right click on website-->Add 
New Item-->Select Sql Server Database-->click Add.Then you can see  that database(.mdf) is added on your website.
see it;

solution explorer
Step 4- If you want to add tables in this database(.mdf),then double click on Database.mdf-->Server Explorer will opened-->Right click on Tables-->Add New Table-->Now fill up column fields-->click save button on visual studio-->Write your table name-->Click ok.Now you will see, Your table will be created.Here i have created a student1 table.
see it:

Note:- You can solve this type of problem in any version of visual studio and Microsoft sql server.  
When some times your Sql server 2008 R2(any) services is not working properly then follow following steps which is given below:
Go Start-->All programs-->Microsoft Sql Server 2008 R2-->Configuration Tools-->Sql Server Configuration Manager-->One popup will open-->click yes-->Now click Sql server Services-->Right click and start each services as shown below:
when you will start above two services then your sql server 2008 R2(any other), will work properly.
 To know more, download this file                   
For More:-
  1. Xml Application
  2. Make Captcha image for Asp.Net Application
  3. Create .dll File and Use in Application 
  4. Interview Questions and Answers
  5. Exception Handling
  6. Transaction in Sql server
  7. Directory and directory info class
  8. Delegate in c#
  9. Namespace in .net
  10. Out parameter in c#
  11. Call by value and call by reference in c#
  12. Interface in c#
I hope this is helpful for you.if any problem please comment it.
Download whole attached application.


  1. Is this necessary to create a empty website to create a database from solution explorer?
    I have a database i want to add that in App_Data,what i have to do?

    1. it is not necessary You can create your database in sql server separately and connect to your website.In this there are no need to add it on the website you can host as it in on your server.yes, you can add it.go solution Explorer--.create App-Data folder -->right click on this folder-->Add Existing items-->select your database file but it should be in .mdf or .sdf format.

    2. When I click --ADD Existing Items-->Selected the database-->this error comes up("Unadle to add(databasesource...Database.mdf) Access is denied)

  2. hello sir
    it was a great experience to work with step by step instructions but i have a problem to add database file due to use of sqlserver2010 please give me help to solve my problem .

  3. hello sir
    i followed your steps for inserting the .mdf file in website but it is showing an error that "The file cannot be opened because it is being in used by another file try it again." Please help me out

    1. Hi deepa ! you have not configured connection string correctly.First change your connection strings from below link

      you can use any connection string instead of your connection strings then It will work definitely.if any problem ask again and share this website to friends.

  4. Thnk uuuuu so much u solved my last pblm....... But I hv one more question... I want to create a table in database.. When I click on table--> right click --> design. Its shows me ( column name, data type, and Allow nulls) when I set this now I want to put a data in this table.... where I put the data.

  5. Replies
    1. hi rumaisa ! first open your solution explorer -->Open Database.mdf file -->
      Right click Tables --> Add New Table -->Now fill your Column Name,Data Type,Allow Nulls fields
      --> Now click Save Button-->Enter your table Name (ex.student) -->OK.
      Now you have created your table(student)with some columns.

      Now Right click your table (ex.student)-->Show Table Data--> Now Write your table (student) values --> save it
      --> Now you have done.

      you can see you table data-->Right click on Table (student)-->click show Table Data

    2. I followed Ur all d steps.... but when I saved a table... then right click on table,, I am not finding any option there ,,Show Table Data..

    3. Hi Rumaisa ! Right click on Your saved table Name (ex. student)-->Show Table Data
      it will work definitely....

  6. i clicked on saved table but still not get Show Table data option.. Cant understand where i enter data..If possible please send SnapShot.

    1. Hi Rumaisa khan ! here i can't post can directly contact me through contact form or email .i will help you definitely..

  7. hiii sir i have done step1,2 but while adding database.mdf file to application its showing same error plzzz help me sir...

    1. hi KALAYANI !
      have you already installed sql database 2008 or other in your system.first install sql database then follow the above steps,then it will work definitely. if you face same problem same again then specify the error message then i will see it..

    2. I am also experiencing the same problem and i have already installed the sql database 2008 in my system

  8. hiii sir i have done all steps but while adding database.mdf file to application its showing same error plzzz help me...

  9. please help me the same error is occuring as shown in first image in your site. please give me a perfect solution for visual studio sql error

  10. hii i am using sql server 2008 r2 , i did follow the steps for solve the problem , but i am not able to see any file , help me

  11. I have follow all ur steps..still the same error come with database


Powered by Blogger.