无法打开数据库“DBNAME”由登录请求。 登录失败(Cannot open database

2019-10-21 07:16发布

我试图让到SQL Server数据库(托管在本地主机)的连接,但不断收到在标题中提到的错误。

    Application("ConnectionString") = "Provider=SQLOLEDB;Data Source=localhost\SQLExpress;Database=mydb;Trusted_Connection=yes;UID=dbadmin; PWD=dbadmin" 
Application("ConnectionTimeout") = 15
Application("CommandTimeout") = 90
Application("CursorLocation") = 3

strQuery = "select * from dec_users"
Set objDBConnection = Server.CreateObject("ADODB.Connection")

objDBConnection.open Application("ConnectionString")
Set RS = Server.CreateObject("ADODB.RecordSet")

RS.Open strQuery, objDBConnection

有任何想法吗?

Answer 1:

你把它错了,更改为:

Application("ConnectionString") = "Provider=SQLOLEDB.1;Integrated Security=SSPI;
        Persist Security Info=False;User ID=dbadmin;Initial Catalog=mydb;
        Data Source=localhost\SQLExpress;Password=dbadmin"

(换行符添加用于易读性)

有疑问时,创建一个.udl文件,使用GUI构建的ConnectionString,然后复制粘贴的ConnectionString(打开与记事本文件)



文章来源: Cannot open database “dbname” requested by the login. The login failed