Click here to Skip to main content
15,901,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to add existing database in app_data folder in asp.net?
Posted
Comments
ridoy 16-Aug-12 7:59am    
just cope and paste your_database.mdf file in app_data folder..

XML
1) first of all i have to deattach database from sql server
a) open sql server
b) connect your server
c) open node of database and right click on your database and choose task menu and then choose deattach then database will deattached

2) In second step in visual studio right click on app_data folder and click on add existing item and then select database which you want to add in app_data folder it will be in In my case ( C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\accountdb.mdf) and now this database will add in app_data folder

3) Now change your connection string in config file
Collapse | Copy Code

<connectionstrings>
        <add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Accountdb.mdf;Integrated Security=True;User Instance=True  " name="ConnectionASPX" providername="System.Data.SqlClient" />
</connectionstrings>




//here |DataDirectory| is path of app_data folder and accountdb is the name of database name can be anything of connectionstring.

Thank You if this solution helps you so please vote for me
 
Share this answer
 
So what is your problem just go ahead.
Right click on your App_Data folder and click on Add Existing Item,
Then select your database and that's it.

The given method works only when your database is detached with SqlServer.
For detaching the database go to your database in Sql Server and then right click on it and select detach option.
then find your database somewhere in c driver:
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data

All the best.
 
Share this answer
 
Comments
veenusethi 17-Aug-12 0:40am    
Thanks for your reply it works
veenusethi 17-Aug-12 0:41am    
But how to bind app_data folder's database with crystal reports
vihangshah 21-Feb-13 4:35am    
but when we use this approach then i can not found database on server at the time of get the connection string or making the connection ???
Member 11631592 3-May-16 8:03am    
but when I am trying to connect it is saying access denied

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900