简体   繁体   English

使用pdo的mssql登录失败,用户“ dbo”登录失败

[英]mssql using pdo fail login getting Login failed for user 'dbo'

IN Microsoft SQL server Management Studio when I run 在运行时在Microsoft SQL Server Management Studio中

EXEC sp_helplogins @LoginNamePattern='mmanlapig\martin'

I get this : 我明白了:

   LoginName           DBName   UserName    UserOrAlias
1  mmanlapig\martin    homis    db_owner    MemberOf
2  mmanlapig\martin    homis    dbo         User    

Then in my code I have : 然后在我的代码中,我有:

define('DBHOST', 'localhost\SQLEXPRESS'); 
define('DBNAME', 'homis'); 
define('DBUSER', 'dbo'); 
define('DBPASS', ''); 
$dbname = "`" . str_replace("`", "``", DBNAME) . "`";
$dbh1 = new PDO("odbc:Driver={SQL Server};Server=" . DBHOST . ";Database=$dbname;", DBUSER, DBPASS);

When I run this code 当我运行这段代码

Select sp.name as LoginName, sp.type_desc as LoginType,
    dp.name as DBUser, dp.type_desc as UserType
from sys.server_principals sp
join sys.database_principals dp on dp.sid = sp.sid
where sp.name = 'mmanlapig\martin';

I get 我懂了

   LoginName           LoginType        DBUser  UserType
1  mmanlapig\martin    WINDOWS_LOGIN    dbo     WINDOWS_USER
  1. Why do I get error saying that i fail in connecting to database when all my login credential is ok. 为什么当我的所有登录凭据都正常时,会出现错误消息,提示我无法连接数据库。
  2. What is the correct username password that I need to use to connect to database? 我需要使用什么正确的用户名密码才能连接数据库?

Tried these steps from here 这里尝试了这些步骤

The issue was that the server was set to "Windows Authentication Mode" only. 问题是服务器仅设置为“ Windows身份验证模式”。 To fix this I 为了解决这个问题

  1. Right click the server - > Properties 右键单击服务器->属性
  2. Click "Security" in the left side of the "Server Properties" dialog 单击“服务器属性”对话框左侧的“安全性”
  3. Changed server Authentication to "SQL Server and Windows Authentication mode" 将服务器身份验证更改为“ SQL Server和Windows身份验证模式”
  4. Clicked "OK" 点击“确定”
  5. Restarted Associated services. 重新启动关联服务。 At first I forgot to restart the services, so I was still getting the error, but now I am able to connect without an issue. 起初我忘记重新启动服务,所以我仍然遇到错误,但是现在我可以无问题地连接了。

Still same issues 还是一样的问题

Hope this article helps you: Using PDO's odbc to connect to a MSSQL server instance with Windows Authentication 希望本文对您有所帮助: 使用PDO的odbc通过Windows身份验证连接到MSSQL服务器实例

$conn = new PDO(
    'odbc:
        Driver=SQL Server;
        Server=MyServer\MyInstance;
        Database=MyDatabaseName;
        Trusted Connection=Yes;'
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM