添加登录并使用SQL Server身份验证连接到SQL [英] Add login and connect to SQL with SQL Server Authentication
问题描述
我想在SQL Server 2008中添加一个用户,所以我可以使用SQL Server身份验证,而不是Windows身份验证连接到SQL,并尝试使用此代码创建一个登录用户:
CREATE login [newLog] with password ='passnewLognewLog'
$ b b
我完成了,但是当我想使用SQL身份验证连接到SQL Server时,我收到此消息
到Mydb
附加信息:用户
登录失败'newLog'。 (Microsoft SQL Server,
错误:18456)
我在这里缺少什么?
创建登录后,需要将用户添加到数据库。此示例来自sql服务器文档,用于 CREATE USER
:
CREATE LOGIN AbolrousHazem
With PASSWORD ='340 $ Uuxwp7Mcxo7Khy';
USE AdventureWorks2008R2;
CREATE USER AbolrousHazem FOR登录AbolrousHazem;
GO
编辑
为了测试,我运行了这个T-SQL:
create login Foo with password ='f00' ;
go
使用TestDB
为登录创建用户Foo Foo
go
并使用此连接字符串成功打开连接:
Server =< server& ; user id = Foo; password = f00; initial catalog = TestDB
I want to add a user in SQL Server 2008 so I can use SQL Server Authentication instead Windows Authentication for connecting to SQL, and have tried this code to create a user with login:
CREATE login [newLog] with password = 'passnewLognewLog'
I get it done, but when I want to connect to SQL Server using SQL Authentication, I get this message
Cannot connect to "Mydb"
additional information: Login failed for user 'newLog'. (Microsoft SQL Server, Error: 18456 )
What am I missing here?
After creating the login, you need to add the user to the database. This example is from the sql server documentation for CREATE USER
:
CREATE LOGIN AbolrousHazem
WITH PASSWORD = '340$Uuxwp7Mcxo7Khy';
USE AdventureWorks2008R2;
CREATE USER AbolrousHazem FOR LOGIN AbolrousHazem;
GO
Edit
To test, I ran this T-SQL:
create login Foo with password ='f00';
go
use TestDB
create user Foo for Login Foo
go
and opened a connection successfully using this connection string:
"Server=<server>; user id=Foo; password=f00; initial catalog=TestDB"
这篇关于添加登录并使用SQL Server身份验证连接到SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!