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

By
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:

error
  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:

default_connection

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:
table

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:
systemproblem
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 Asp.net 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.
      Download

20 comments:

  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?

    ReplyDelete
    Replies
    1. it is not necessary You can create your database in sql server separately and connect to your asp.net 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.

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

      Delete
  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 .

    ReplyDelete
  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

    ReplyDelete
    Replies
    1. Hi deepa ! you have not configured connection string correctly.First change your connection strings from below link
      http://www.msdotnet.co.in/2013/12/how-to-use-different-connection-strings.html

      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.

      Delete
  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.

    ReplyDelete
  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

      Delete
    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..

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

      Delete
  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.

    ReplyDelete
    Replies
    1. Hi Rumaisa khan ! here i can't post snapshot.you can directly contact me through contact form or email msdotnet@hotmail.com .i will help you definitely..

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

    ReplyDelete
    Replies
    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..

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

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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete

Powered by Blogger.