简体   繁体   中英

Database is removed from Microsoft SQL Server, Why?

I created a new Empty website in Visual studio Express 2013. I created an ASP.NET folder: App_Data.

Then I went to SQL Server Management Studio. I created a new Database in which I provided the path to the App_Data of the website that I created.

I named the database "FacebookData"

Then I went to Visual studio; I found the database in the App_Data folder and also in Server Explorer.

I went to Web.config, And under I added

  <connectionStrings>
    <add name="DataConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\FacebookData.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

I click Build -> Rebuild Solution

When I close SQL Server Management Studio, and reopen it again. The Database named "FacebookData" is missed from the SQL Server Management Studio Databases list!!!.

I still find it in the Visual Studio in App_Data folder and Server Express.

If I close and open the SQL Server Management Studio before adding the to the Web.config. The Database is still exist in the SQL Server Management Studio. which makes me feel that there is something wrong in the connection string.

Any clues?

Your connection string says that database should be "attached" to SQL server when application is run. To have it permanently living in SQl server you should just use SQL server management studio to attach it manually, that way it stays attached. You also need to change you connection string to

"Server=your_sql_server_instance;Database=FacebookData;Integrated Security=True"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM