且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在asp.net的app_data文件夹中添加现有数据库

更新时间:2023-09-26 10:57:40

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


所以,您要解决的问题只是继续.
右键单击您的App_Data文件夹,然后单击添加现有项,
然后选择您的数据库即可.

仅当使用SqlServer分离数据库时,给定方法才有效.
要分离数据库,请在Sql Server中转到数据库,然后右键单击它并选择detach选项.
然后在c驱动程序中的某个位置找到数据库:
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data

一切顺利.
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.