VB.NET Simultaneous connections LocalDB Database

放肆的年华 提交于 2019-12-13 08:04:07

问题


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.

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"

回答1:


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

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.

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.




回答2:


I may have an alternative idea. Due to that file being local and multiple users are accessing it. You could always host the database online and then link into the databse that way. which will then allow all of the edits to the database to be instant.



来源:https://stackoverflow.com/questions/36022498/vb-net-simultaneous-connections-localdb-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!