简体   繁体   English

建议使用数据库部署C#程序以在LAN上工作

[英]Advice for deploying a C# program with database to work over LAN

I've designed a C# game that makes use of an Access .mdb database file to store variables. 我设计了一个C#游戏,它利用Access .mdb数据库文件来存储变量。

The basic idea is that one of the players will 'host' a game, and the other player will join said game, by connecting to the database, reading and writing items into the database. 基本思想是其中一个玩家将“主持”一个游戏,另一个玩家将加入所述游戏,通过连接到数据库,读取和写入数据库中的项目。 The database is needed to pass variables to and fro the host and client, and both programs check the database regularly for new messages / variables (yes, yes, I couldn't get TCP/IP Remoting to work). 需要数据库来传递主机和客户端之间的变量,并且两个程序都会定期检查数据库中的新消息/变量(是的,是的,我无法使TCP / IP Remoting工作)。

Now, there, the program works fine (mostly the client, since the host modifies only its local database), for as long as the client can find the database file. 现在,只要客户端可以找到数据库文件,程序就可以正常工作(主要是客户端,因为主机仅修改其本地数据库)。 Currently, the connection string for the client is located in a .ini file, and for the program to work, it (or at least, the server) must be located in the Shared Documents of an XP machine, or the Public Documents of a Vista / 7 machine. 目前,客户端的连接字符串位于.ini文件中,要使程序正常工作,它(或至少是服务器)必须位于XP机器的共享文档中,或者公共文档中。 Vista / 7机器。

But then some questions occurred to me: 但后来我遇到了一些问题:

  1. What if the client user places / installs it into another folder in the Shared / Public Documents? 如果客户端用户将其/安装到共享/公共文档中的另一个文件夹中该怎么办? I suppose there's a code out there that could 'drill' into the Shared Documents folders to find the path for the database, share names included... is there? 我想有一个代码可以“钻”到共享文档文件夹中以查找数据库的路径,包括共享名称......是吗?

  2. What about installation? 安装怎么样? The installer default is always "C:\\Program Files\\GameName". 安装程序默认值始终为“C:\\ Program Files \\ GameName”。 Could it be set (or locked) to a specific folder into the Shared / Public Documents, by default? 默认情况下,是否可以将特定文件夹设置(或锁定)到共享/公共文档中? And is it even recommended to install it into a Shared Folder, what with problems such as Accidental Deletion? 是否甚至建议将其安装到共享文件夹中,以及诸如意外删除等问题?

  3. Say, the default is "C:\\Program Files\\GameName". 比如说,默认为“C:\\ Program Files \\ GameName”。 I could see that a set installation path will solve any connection issues, since every client will look in the same path of the other computer, and it won't matter if it's XP or Vista. 我可以看到一个设置的安装路径将解决任何连接问题,因为每个客户端将查看另一台计算机的相同路径,并且无论是XP还是Vista都无关紧要。 Could "C:\\Program Files\\GameName" be accessible by a C# program over LAN, without any system modification? 可以通过LAN上的C#程序访问“C:\\ Program Files \\ GameName”,而无需进行任何系统修改吗? Are there any security (UAC?) issues? 有任何安全性(UAC?)问题吗?

PS Details that people may find in handy: I'm using Visual Studio 2005. So is my School. PS人们可能会发现方便的细节:我正在使用Visual Studio 2005.我的学校也是如此。 I'm running .NET framework 2.0. 我正在运行.NET framework 2.0。 So is my school, and unfortunately, I can't change that. 我的学校也是如此,不幸的是,我无法改变这一点。

Get rid of the access database. 摆脱访问数据库。 The described architecture is already 'user unfriendly' 所描述的架构已经“用户不友好”

Use either SQL Express or SQL CE which requires no installed database binaries (they can all be included in the applications folder). 使用SQL Express或SQL CE,它不需要安装数据库二进制文件(它们都可以包含在applications文件夹中)。 This way the db will stay in the applications folder (ideally app_Data) and .Net has included support for databases in this folder. 这样,数据库将保留在应用程序文件夹(理想情况下为app_Data)中.Net已包含对此文件夹中数据库的支持。

Please stay away from access you will save yourself a lot of trouble. 请远离访问,您将省去很多麻烦。

http://blogs.msdn.com/b/sqlservercompact/archive/2011/01/12/microsoft-sql-server-compact-4-0-is-available-for-download.aspx http://blogs.msdn.com/b/sqlservercompact/archive/2011/01/12/microsoft-sql-server-compact-4-0-is-available-for-download.aspx

I hate to tell you this, but this is why the approach is fundamentally flawed. 我不想告诉你这个,但这就是为什么这种方法存在根本缺陷的原因。 What are you going to do when: 你有什么打算做的:

  • File and print sharing on the server is disabled? 服务器上的文件和打印共享被禁用?
  • The network client is disabled on a client computer? 客户端计算机上禁用了网络客户端?
  • The server is configured to only allow authenticated users, and the client doesn't have access? 服务器配置为仅允许经过身份验证的用户,并且客户端无权访问?
  • File and print sharing is blocked because of the firewall? 由于防火墙,文件和打印共享被阻止了?
  • File and print sharing is completely borked for other who-knows-why reasons? 文件和打印共享完全被其他谁知道原因所困扰?
  • You need administrator access on the server to share a folder, but the current user is not an administrator? 您需要在服务器上具有管理员访问权限才能共享文件夹,但当前用户不是管理员?
  • The Access database engine isn't installed correctly on the server or client? Access数据库引擎未在服务器或客户端上正确安装?
  • One of the clients corrupts the database? 其中一个客户端破坏了数据库? (This is easier than you might think; all it takes is a network glitch where a client temporarily or permanently disconnects from the server). (这比您想象的要容易;只需要一个网络故障,客户端暂时或永久地断开与服务器的连接)。

These are fundamental issues that you can't resolve with the current solution. 这些是您无法使用当前解决方案解决的基本问题。

Get it working over normal TCP/UDP ports. 让它在正常的TCP / UDP端口上运行。 You'll have a much easier time. 你会有更轻松的时间。 There are libraries to facilitate that, see C# Game Network Library - for example it sounds like Microsoft's XNA SDK has functions for networking in a game. 有一些库可以促进这一点,参见C#游戏网络库 - 例如,听起来微软的XNA SDK具有在游戏中进行网络连接的功能。 If you use a standard method / standard library to implement networking, your odds of success are much higher. 如果您使用标准方法/标准库来实现网络,您的成功几率要高得多。 Using a client/server architecture means that the server's state won't be corrupted if a client goofs up. 使用客户端/服务器体系结构意味着如果客户端搞砸了,服务器的状态将不会被破坏。

I realize that this probably involves a significant rewrite. 我意识到这可能涉及重大改写。 Frankly, I don't think you have a choice if you want this game to be commercially successful on a wide customer base without high support costs, and move beyond being a mere experiment. 坦率地说,如果你希望这款游戏在没有高昂支持成本的情况下在广泛的客户群中取得商业成功,我认为你没有选择,并且不仅仅是一个实验。

I think that there is little point in using Access unless you wanted to use any of the pretty form-based IO that you can you do with its designer. 我认为使用Access没有什么意义,除非您想使用任何基于表单的漂亮IO,您可以使用它的设计器。 And I doubt that'll be the case here. 而且我怀疑这将是这种情况。

I would encourage you to replace all your file IO with a sound data access layer. 我建议您使用声音数据访问层替换所有文件IO。 Which will rid you of all the "sharing" issues that you are experiencing, file locks, the overcomplicated installation process, etc. 这将解除您遇到的所有“共享”问题,文件锁定,过于复杂的安装过程等。

Alternatively to SQL Server Express as suggested above you could also use SQLite http://code.google.com/p/csharp-sqlite/ 除了上面建议的SQL Server Express之外,你也可以使用SQLite http://code.google.com/p/csharp-sqlite/

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

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