[英]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. 不完全确定这一点,但尝试一下。
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.