无法打开数据库" DBNAME"登录所请求。登录失败 [英] Cannot open database "dbname" requested by the login. The login failed

查看:188
本文介绍了无法打开数据库" DBNAME"登录所请求。登录失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做出SQL Server数据库(托管在localhost)的连接,但不断收到在标题中提到的错误。

I'm trying to make a connection to sql server database(hosted on localhost) but keep getting the error mentioned in the title.

    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

什么想法?

推荐答案

您是把它错了,更改为:

You are putting it wrong, change to:

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

(换行增加了可读性)

(Linebreaks added for legibility)

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

When in doubt, create a .UDL file, construct the ConnectionString using the GUI, and then copy paste the ConnectionString (opening the file with notepad)

这篇关于无法打开数据库" DBNAME"登录所请求。登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆