VB.NET同时连接LocalDB数据库 [英] VB.NET Simultaneous connections LocalDB Database

查看:162
本文介绍了VB.NET同时连接LocalDB数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用一些LocalDB数据库(.mdf文件).我一直是唯一使用这些数据库的人,但是现在越来越多的人在使用它.每次我们同时使用该应用程序时,都会出现错误,因为我们同时连接到数据库.

I've been using some LocalDB databases (.mdf files). I've been the only one using those DB for a while, but more and more are using it now. Every time we use the app at the same time we have an error because we connect to the DB at the same time.

是否有允许同时连接到SQL LocalDB数据库的方法? 如果不是,最好的替代方法是假设我们永远不会有超过5个人同时连接?

Is there a way to allow simultaneous connections to an SQL LocalDB database? If not what is the best alternative assuming we will never have more than 5 people connecting at the same time?

这是我要访问我的数据库文件的代码:

Here is the code i'm suing to acess my DB file :

Public Shared Function SQLQuery(query As String, connectionString As String, tableName As String)
    Dim cn As New SqlConnection(connectionString)
    Dim cm As New SqlCommand(query, cn)
    Dim adp As New SqlDataAdapter(cm)
    Dim ds As New DataSet
    adp.Fill(ds, tableName)
    adp.Dispose()
    cm.Dispose()
    cn.Close()
    SQLQuery = ds
End Function

这是连接字符串的示例:

And here is an example of connection string :

Public Shared connectionStringScreenDataDB As String = "Data Source=(LocalDB)\v11.0;AttachDbFilename='P:\Clement\Visual Studio\PanoramaFund2App\PanoramaFund2App\ScreenDataDB.mdf';Integrated Security=True"

推荐答案

LocalDB允许无限的(本地)并发连接;参见 SQL Express v LocalDB v SQL Compact Edition

LocalDB allows for unlimited (local) concurrent connections; see SQL Express v LocalDB v SQL Compact Edition

您的连接字符串似乎指向共享驱动器. LocalDB不接受远程连接.共享网络文件夹的想法可能行得通(不过,我对此表示怀疑).请记住,只有一个LocalDB实例可以同时打开任何给定的数据库文件(和日志文件).

Your connections string appears to point to a shared drive. LocalDB doesn't accept remote connections. The idea with shared network folder might work (I doubt it though); keep in mind that only one LocalDB instance can have any given database file (and log file) open at the same time.

替代方案:简化表示,LocalDB的目的是在一台机器上本地用于一个应用程序.如果需要远程访问,则可以使用SQL Server(非Express版)或任何其他数据库.

Alternatives: Simplified said, LocalDB's purpose is to be used locally for one application on one machine. If you need remote access you can use SQL Server (not the Express edition) or any other database.

这篇关于VB.NET同时连接LocalDB数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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