即使多用户处于活动状态,SQL DB也只能由单个用户访问

时间:2018-06-08 13:14:57

标签: c# sql database multi-user

我在C#项目中使用SQL数据库,我想让多个用户可以访问它。我已经检查过,它确实处于多用户模式,但我仍然收到一个错误,告诉我我无法连接同一个数据库中的多个用户。有谁知道我能做些什么来解决它?可能是代码有问题吗?

使用Linq进行数据库访问:

var queryline = from anmeldung in context.Accounts
                            where anmeldung.Benutzername == BN
                            where anmeldung.Passwort == PW
                            select anmeldung.Id;

App.config中:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="DBtest.Properties.Settings.TestConnectionString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Test.mdf;Integrated Security=True;Connect Timeout=10"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

错误消息:

  

System.Data.SqlClient.SqlException HResult = 0x80131904 Nachricht =   连接到SQL时与网络相关或特定于实例的错误   服务器。找不到或无法访问服务器。验证   实例名称是正确的,SQL Server允许远程   连接..(提供者:命名管道提供者,错误:40 - Verbindung   mit SQL Server konntenichtgeöffnetwerden)Quelle = .Net SqlClient   数据提供商Stapelüberwachung:bei   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity   identity,SqlConnectionString connectionOptions,SqlCredential   凭证,Object providerInfo,String newPassword,SecureString   newSecurePassword,Boolean redirectedUserInstance,SqlConnectionString   userConnectionOptions,SessionData reconnectSessionData,   DbConnectionPool池,String accessToken,Boolean   applyTransientFaultHandling)bei   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions   options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,   DbConnectionPool池,DbConnection owningConnection,   DbConnectionOptions userOptions)bei   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(类DBConnectionPool   pool,DbConnection owningObject,DbConnectionOptions选项,   DbConnectionPoolKey poolKey,DbConnectionOptions userOptions)bei   System.Data.ProviderBase.DbConnectionPool.CreateObject(的DbConnection   owningObject,DbConnectionOptions userOptions,DbConnectionInternal   oldConnection)bei   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(的DbConnection   owningObject,DbConnectionOptions userOptions,DbConnectionInternal   oldConnection)bei   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(的DbConnection   owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean   allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions   userOptions,DbConnectionInternal&amp;连接)bei   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(的DbConnection   owningObject,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) bei System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource 1重试,DbConnectionOptions   userOptions,DbConnectionInternal oldConnection,DbConnectionInternal&amp;   连接)bei   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(的DbConnection   outerConnection,DbConnectionFactory connectionFactory,   TaskCompletionSource 1 retry, DbConnectionOptions userOptions) bei System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1次重试,DbConnectionOptions userOptions)bei   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource 1 retry) bei System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource 1   重试)bei System.Data.SqlClient.SqlConnection.Open()bei   System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser   user)bei System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
  bei System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
  北   System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式   查询)bei   System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()   bei DBtest.Program.Register(Int32&amp; ID)in   \ 192.168.2.1 \ Share \ DBtest \ DBtest \ Program.cs:Zeile61 bei   DBtest.Program.Main(String [] args)in   \ 192.168.2.1 \ Share \ DBtest \ DBtest \ Program.cs:Zeile102

     

Innere Ausnahme 1:Win32Exception:DasZeitlimitfürdieSemaphore   wurde erreicht

0 个答案:

没有答案