Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用服务器登录的C#SQL Server连接_C#_Sql Server_Login_Connection - Fatal编程技术网

使用服务器登录的C#SQL Server连接

使用服务器登录的C#SQL Server连接,c#,sql-server,login,connection,C#,Sql Server,Login,Connection,我在连接SQL server时遇到问题。我不断收到“用户登录失败”错误消息,但我尝试登录的用户作为登录名存在于服务器上。我使用的连接字符串如下所示: Data Source=[server name];Initial Catalog=[database];User ID=[login name];Password=[login password]; 是因为登录名存在于服务器上,而不是作为数据库上的用户,所以我不能使用它登录吗 如果是这样,我是否无法使用服务器登录连接到服务器 提前感谢。可能是您

我在连接SQL server时遇到问题。我不断收到“用户登录失败”错误消息,但我尝试登录的用户作为登录名存在于服务器上。我使用的连接字符串如下所示:

Data Source=[server name];Initial Catalog=[database];User ID=[login name];Password=[login password];
是因为登录名存在于服务器上,而不是作为数据库上的用户,所以我不能使用它登录吗

如果是这样,我是否无法使用服务器登录连接到服务器


提前感谢。

可能是您的连接字符串有其他问题。我知道如果我的字符串中有错误的数据库或服务器,它将给我一条“无法使用用户登录…”消息


数据源=[服务器名称];初始目录=[数据库];用户ID=[登录名];密码=[登录密码]

可能是您的连接字符串有其他问题。我知道如果我的字符串中有错误的数据库或服务器,它将给我一条“无法使用用户登录…”消息


数据源=[服务器名称];初始目录=[数据库];用户ID=[登录名];密码=[登录密码]

使用此代码连接SQL Server(首选语言为C#)


使用此代码连接SQL Server(首选语言为C#)


正确:您需要将用户登录添加到数据库。正确:您需要将用户登录添加到数据库。
    Public Sub Start_DB_Connection(servername As String,user As String,password As String,dbname As String)
        Try
            db_con As New SqlConnection
            If Not db_con Is Nothing Then db_con.Close()
            db_con.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; connection timeout=1;", servername, user, password, dbname)

            db_con.Open()
        Catch ex As Exception
            // show error
        End Try
    End Sub