如何在Windows窗体应用程序中同时与数据库多个连接 [英] How do I multiple connection with database at same time in windows form application

查看:215
本文介绍了如何在Windows窗体应用程序中同时与数据库多个连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何共享数据库意味着我们如何同时为两个相同的软件使用相同的数据库?

我的工作

i在两台 PC 之间制作服务器并共享我的.mdf和.ldf文件

然后我安装尝试在 PC上运行我的项目在同一时间但却抛出错误登录失败

请帮我完成我的项目

谢谢你



我尝试过:



用于连接我用过这个

how can we share data base means how can we use same database at same time for two same software ?
My working
i made server between two PC and share my .mdf and .ldf files
then i install try to run my project on both PC at same time but it throw an error "login fail"
please help me to complete my project
THANK YOU

What I have tried:

for connection i used this

<appsettings><br />
    <add key="con" value="Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\MTS\database\MTS.mdf;Integrated Security=True;Connect Timeout=30" /><br />
  </appsettings>

推荐答案

您正在尝试附加一个特定PC的本地数据库 - 它位于D驱动器上。

除非您以某种方式设法连接相同的硬盘驱动器到两台PC,这是不可能的...

而不是附加你的MDF,在SQL Server实例中创建数据库,让SQL Server处理保存的位置它。

我强烈建议集成安全性是一个坏主意:创建SQL服务器用户,并以其中一个登录。这样,您可以限制用户应用程序对数据的访问。例如,如果您的应用程序容易受到SQL注入的影响,您可以拒绝DROP TABLE请求。
You are trying to attach a DB which is local to a specific PC - it's on the D drive.
Unless you have somehow managed to connect the same HDD to two PCs, that isn't likely to work...
Instead of attaching your MDF at all, create the database in the SQL Server instance and let SQL Server handle where to keep it.
And I'd strongly suggest that Integrated Security is a bad idea: create SQL server users, and log in as one of those. That way, you can limit the access a user application has o data. For example you can refuse DROP TABLE requests, in case your app is susceptible to SQL Injection.


这篇关于如何在Windows窗体应用程序中同时与数据库多个连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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