遇到“无效的授权说明”这种错误问题的兄弟来一下! 已经找了大把贴子了,没有能解决的

混世罗汉 2007-05-12 10:39:10
用vb连接sqlserver2000,用以下语句能正常访问:

cn.Open "Provider=SQLOLEDB;Data Source=localhost;User ID=sa;Password=ren;Initial Catalog=savesms;Persist Security Info=True"

现在公司要求服务器名、数据库名、登录用户和密码要从.ini文件中读取,现在读取ini文件里的变量没有问题,可连接语句改成下面的就有提示:无效的授权说明

cn.Open "Provider=SQLOLEDB;Data Source=" & tempserver1 & " ;User ID=" & tempusername1 & " ;Password=" & tempuserpassword1 & " ;Initial Catalog= " & tempdatabasename1 & " ;Persist Security Info=True"

更奇怪的是 tempserver1,tempusername1等4个变量的值都已经得到了,就是读出来了。还是不能正常执行这条sql语句,

一定非要把:
tempserver1 = "localhost"
tempusername1 = "sa"
tempuserpassword1 = "ren"
tempdatabasename1 = "savesms"
这样的赋值变量写上才能正常执行sql语句,晕,请高手们给个说法。
公司要求 不能把数据库都配置说明直接写入程序,要可以自己控制,所以要写在.ini文件中,求你们了。
...全文
1133 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
混世罗汉 2007-05-14
  • 打赏
  • 举报
回复
谢谢了
jadeluo 2007-05-14
  • 打赏
  • 举报
回复
估计是从INI文件中读出的值不正确, 末尾有一个0号字符(vbNullChar)

把tempserver1、 tempusername1、tempuserpassword1、tempdatabasename1四个变量用下面的函数进行处理:

Public Function StringProcess(ByVal S As String) As String
Dim i As Long
i = InStr(S, vbNullChar)
If i > 0 Then
StringProcess = Left(S, i - 1)
Else
StringProcess = S
End If
End Function

......

tempserver1 = StringProcess(tempserver1)
tempusername1 = StringProcess(tempusername1)
tempuserpassword1 = StringProcess(tempuserpassword1)
tempdatabasename1 = StringProcess(tempdatabasename1)

......
daisy8675 2007-05-14
  • 打赏
  • 举报
回复
strConn="Provider=SQLOLEDB;Data Source=" & tempserver1 & " ;User ID=" & tempusername1 & " ;Password=" & tempuserpassword1 & " ;Initial Catalog= " & tempdatabasename1 & " ;Persist Security Info=True"

debug.print strConn

然后自己看到底那里出了问题
iamtsfw 2007-05-13
  • 打赏
  • 举报
回复
debug.print tempserver1 & "--" & len(tempserver1) '= "localhost"
debug.print tempusername1 & "--" & len(tempusername1) '= "sa"
debug.print tempuserpassword1 & "--" & len(tempuserpassword1) '= "ren"
debug.print tempdatabasename1 & "--" & len(tempdatabasename1) '= "savesms"
打印出结果再对比localhost...
混世罗汉 2007-05-13
  • 打赏
  • 举报
回复
去掉字符结束符试试?????//什么意思
混世罗汉 2007-05-13
  • 打赏
  • 举报
回复
取值正确,
CathySun118 2007-05-13
  • 打赏
  • 举报
回复
看看取的值是否正确,去掉字符结束符试试

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧