简体   繁体   English

C#Express Edition + SQL Server 2008 R2 Express; 正在运行时重新创建的数据库文件

[英]C# Express Edition + SQL Server 2008 R2 Express; Database file being recreated on run

I created a standard C# console application in 2010 Express, used the wizards to create a simple sql express db file which gets placed in the project dir, used the wizards to generate an entity data model based on the newly created db, wrote a few lines to test out entity. 我在2010 Express中创建了一个标准的C#控制台应用程序,使用向导创建一个简单的sql express db文件,它放在项目目录中,使用向导根据新创建的db生成实体数据模型,写了几行测试实体。

Problem is each time I run the application it recreates the DB file in whatever dir the exe is in overwriting itself everytime and completly ignoring the original db file that sits in the project dir. 问题是每次我运行应用程序时,它都会重新创建DB文件,无论exe在每次覆盖自己的目录中是什么,并且完全忽略了位于项目目录中的原始db文件。

Does anyone know what I am missing here ? 有谁知道我在这里缺少什么?

Not entirely sure about this but try it out. 不完全确定这一点,但尝试一下。

  1. Make sure your connection string points to the database file in the project directory. 确保连接字符串指向项目目录中的数据库文件。
  2. Select the file in Visual Studio and Choose 'Copy to Output Directory' ->> Do Not Copy. 在Visual Studio中选择文件,然后选择“复制到输出目录” - >> 不复制。

Hope it works. 希望它有效。

you must be using some way to find that file or some path parameter within the database connection that points to the database file. 您必须使用某种方式在数据库连接中查找指向数据库文件的文件或某个路径参数。 Now either you can have that parameter be generated by code or make the directory specific and make the database file copy at a specific location from the original location so that the only that particular database is accessed using the application. 现在要么您可以通过代码生成该参数,要么使该目录特定,并使数据库文件从原始位置复制到特定位置,以便使用该应用程序访问该特定数据库。 For doing that you can add another key in the application config file or at some other place so that the database your application is accessing is in the project directory itself at all times. 为此,您可以在应用程序配置文件或其他位置添加另一个密钥,以便应用程序访问的数据库始终位于项目目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 删除数据库SQL Server 2008 R2 Express Edition-异常 - Drop Database SQL Server 2008 R2 Express Edition - Exception 使用C#安装SQL Server 2008 R2 Express - Install SQL Server 2008 R2 Express using C# SQL Server 2008 R2 Express和每晚的C#数据库更新作业需要在发生故障时“回滚”整个数据库 - SQL Server 2008 R2 Express and nightly C# database update job needs to “rollback” entire database on failure 在SQL Server 2008 R2 Express中存储XML文件 - Storing XML file in SQL Server 2008 R2 express SQL Server 2008 R2 Express还原 - SQL Server 2008 R2 Express restore 卸载SQL Server Express 2005,然后在C#ClickOnce Winform应用程序中安装SQL Server 2008 R2 Express - Uninstall SQL Server Express 2005 then install SQL Server 2008 R2 Express in C# ClickOnce Winform App 适用于Microsoft SQL Server Express 2008 R2的VS C#constring - VS C# constring for Microsoft SQL Server Express 2008 R2 在C#Windows应用程序中使用MS SQL SERVER 2008 R2 EXPRESS? - Use of MS SQL SERVER 2008 R2 EXPRESS with C# Windows Application? 无法以编程方式创建数据库文件(SQL Server 2008 R2 Express) - Cannot create database file programmatically (SQL Server 2008 R2 Express) 具有SQL 2008 R2开发人员和SQL Express 2008 R2的ASP.Net C#ASPNETDB.mdb - ASP.Net C# ASPNETDB.mdb with SQL 2008 R2 Developers and SQL Express 2008 R2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM