使用本地数据库开发sql应用程序
我正在启动一个将与 Microsoft SQL 数据库交互的应用程序(c#、.net)。我需要多个客户端同时访问数据的能力,因此我将使用基于服务的数据库 (.mdf)。是否可以使用本地数据库 (.sdf) 开发应用程序,然后在部署时轻松将其切换到基于服务的数据库?这种类型的开发通常是这样进行的吗?
I am starting an application (c#, .net) that will interact with a Microsoft SQL database. I need the ability for multiple clients to access the data concurrently so I an going to use a service based database (.mdf). Is it possible to develop the application using a local database (.sdf) and then easily switch it over to a service based database when it comes time for deployment? Is that how this type of development it typically done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以通过在 .config 文件中提供数据库的连接字符串来控制数据源。
您甚至可以使用不同的连接字符串创建 .config 文件的调试和发布版本。调试可以指向您的本地计算机并发布到生产环境。
You can control the data source by providing connection string to your database in .config file.
You can even create Debug and Release versions of your .config file with different connection strings. Debug can point to your local machine and Release to production.
开发商店各不相同,但在本地使用 SQL Express 开发应用程序,然后在生产环境中使用 SQL Server 的完整安装是很常见的。
我唯一建议的是确保您为开发环境选择的数据库支持与您在生产中期望的功能相同的功能。例如,当您希望在生产中使用 Oracle 时,请勿在开发设备上使用 SQL Express。
Development shops vary, but it is pretty common to develop apps using SQL Express locally and then use a full installation of SQL Server for the production environment.
The only thing I would advise is make sure that the DB you chose for your dev environment supports the same features as what you expect in production. For example don't use SQL Express on your dev box when you expect to use Oracle in production.
如果两个后端中的数据库架构完全相同,那么您唯一需要做的就是在准备迁移到基于服务的数据库时更改连接字符串。
请注意,架构中最轻微的更改都可能(并且可能会)导致问题。
If the database schema in both backends is exactly the same than the only thing you will need to do is change the connection string when you are ready to move to the service based database.
Be aware that the slightest change in the schema can (and probably will) cause problems.
您想使用 SQL Compact Edition(正如您所说的数据库文件扩展名是 .sdf),对吗?您可以使用 MSSQL Express Edition,因为它的行为更像完整的 MSSQL Server,并且仍然免费,并且在开发人员的计算机上安装并不难(我个人更喜欢此选项)。两者之间存在差异(如下所述:http://blog.sqlauthority.com/2009/04/22/sql-server-difference- Between-sql-server-compact-edition-ce-and-sql-server-express-edition/ )。如果您不想在数据库中使用触发器/过程/视图等功能,您仍然可以使用 CE。
You want to use SQL Compact Edition (as you said database file extension is .sdf), right? You can use MSSQL Express Edition instead, as it acts more like full MSSQL Server, and is still free and not so hard to install on developer's machine (I personally prefer this option). There are differences between the two (as explained here: http://blog.sqlauthority.com/2009/04/22/sql-server-difference-between-sql-server-compact-edition-ce-and-sql-server-express-edition/). If you don't want features like triggers/procedures/views in your database, you can still use CE, though.
如果您有多个客户端,那么您应该使用 SQL Server Express(.mdf 文件) - 当您构建要部署在客户端计算机上并独立运行的应用程序(例如 Windows)时,SQL Server Compact(.sdf 文件)非常有用带有本地数据库的表单应用程序。 SQL Server Compact 只是 MS Access .mdb 文件或 SQLite(所谓的“嵌入式数据库”)的替代品,而 SQL Server Express 是真正的数据库服务器(尽管有一些限制使其不适合大型商业应用程序),并且应该用于多个客户端使用中央数据库的情况,例如Web应用程序和智能客户端应用程序(不过后者也可以使用本地嵌入式数据库)。
If you have multiple clients then you should use SQL Server Express (.mdf file) - SQL Server Compact (.sdf file) is useful when you are building an application that is going to be deployed on client machines and will run standalone, e.g. windows forms application with a local database. SQL Server Compact is just an alternative for MS Access .mdb files or SQLite, the so called "embedded databases", while SQL Server Express is a real database server (albeit with some limitations to render it unsuitable for large commercial applications) and should be used in the cases where multiple clients use central database, e.g. web applications and smart client apps (the latter could also make use of a local embedded database though).