在c#和MSSQL中在运行时更改数据库文件 [英] changing database file at runtime in c# and MSSQL

查看:50
本文介绍了在c#和MSSQL中在运行时更改数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨谢尔盖·亚历山德罗维奇



我想我无法解释。让我这样说吧





我有一个用c#.net和MSSQL服务器开发的财务应用程序。现在假设我的数据库文件名是dbfa2012.mdf。客户端使用此数据库2012年,一年后我为2013年制作了一个新的空白数据库dbfa2013.mdf。所以我希望有一个界面,客户端可以选择他选择的数据库dbfa2012或dbfa2013并工作



提前感谢



Pradeep

Hi Sergey Alexandrovich

I think i am not able to explain. let me put it in this way


i have a financial application developed in c#.net and MSSQL server. now suppose my database file name is dbfa2012.mdf. ihe client uses this database for year 2012 and after one year i make a fresh blank database dbfa2013.mdf for year 2013. so i want to have a interface where the client can select database dbfa2012 or dbfa2013 of his choice and work

thanks in advance

Pradeep

推荐答案

Bad ,真是个坏主意。即使您现在不需要任何完整性,将来也可能遇到问题。不要使用单独的数据库。只是不要。



-SA
Bad, really bad idea. Even if you don't need any integrity now, in future you may run into problem. Don't work with separate databases. Just don't.

—SA


其实这个想法本身并不坏 - 但取决于应用程序。有没有想过什么是模型数据库呢?好吧,Microsoft正在使用有关数据库服务器的独特视图。许多RDBMS使用数据库作为与应用程序相关的顶级概念。微软拥有更高的级别:实例。 SQL Server的实例旨在专用于应用程序。 模型数据库 [ ^ ]是新创建的数据库的模板。实际上,如果您创建一个好的模板并将实例专用于应用程序,您可以遵循当前的概念,只需使用SMO 枚举数据库 [ ^ ]。

但我必须强调,根据微软自己的愿景,这是一种非常特殊的方式。在SQL服务器中,在同一服务器实例的数据库(目录)之间分发数据并没有什么不妥,它们可以透明地工作。使用这种方法比使某些表超出可用性限制更好 - 甚至索引都有它的局限性。

如果你采用这条路径,我建议你为这个路径创建一个单独的数据库。与年份无关的数据,如合作伙伴数据等。



另一种方法,您可以使用它来划分与年份相关的表格,请看这里: http://databases.about.com/od/sqlserver/a/partitioning.htm [ ^ ]。



选择最佳方法需要更深入地了解应用程序架构,数据模型和业务逻辑。
Actually the idea itself is not that bad - but depends on the application. Ever wondered what is the model database is all about? Well, Microsoft is using an unique view about the database server. Many RDBMS use the database as top level concept related to an application. Microsoft has an ever higher level: the instance. An instance of an SQL Server is intended to be dedicated to an application. The model database[^] is the template for newly created databases. So practically, if you create a good template and dedicate the instance to the application, you can follow your current concept, and simply use SMO to enumerate databases[^].
But I have to emphasize, that this is a very special way to do it, based on Microsoft's own vision. In SQL server it is nothing bad in distributing your data between databases (catalogs) of the same server instance, they work transparently. It is better using this approach than allowing some tables to grow beyond a usability limits - even indexing has it's limitations.
If you take this path, I suggest you create a separate database for the data that is not year-related, like partner data and so on.

An other approach, you can use to partition your year related tables, take a look here: http://databases.about.com/od/sqlserver/a/partitioning.htm[^].

Choosing the best approach necessitates deeper knowledge about the application architecture, data model and business logic.


configuring-connection-string-in-app-config-file-during-runt/ [<一个href =http://www.c-sharpcorner.com/UploadFile/1a81c5/configuring-connection-string-in-app-config-file-during-runt/target =_ blanktitle =New Window> ^ ]



如何在运行时更改c#中的连接字符串 [ ^ ]



检查链接..希望它会有帮助......
configuring-connection-string-in-app-config-file-during-runt/[^]

how to change connection string at run time in c#[^]

Check the links..hope it will help...


这篇关于在c#和MSSQL中在运行时更改数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆