描述不太清楚。
用编程语言或脚本连接数据库时,会有这么一行字符串:
StrCnn="Provider=MSDASQL.1;Persist Security Info=True;Extended Properties='Driver=MySQL ODBC 5.3 Unicode Driver;SERVER=10.1.3.133;UID=koa;PWD=koa;DATABASE=koa;PORT=3307'"
或是
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
一.新建记事本,重命名后缀名为udl
二.双击打开这个文件
记得勾选“允许保存密码”,点击下方“测试连接”,连接通过,即配置正确。
三.用记事本打开该文件
这个文件的第三行,即我们需要的字符串。
四.VBScript连接示例
Set fso = CreateObject("Scripting.FileSystemObject")
Set WriteFile = fso.OpenTextFile(DatePart("yyyy",date)&Right("0" & DatePart("m",date), 2)&Right("0"&DatePart("d", date),2)&".txt", 8, True)
'连接数据库
StrCnn="Provider=SQLOLEDB.1;Password=fsdx123;Persist Security Info=True;User ID=sa;Initial Catalog=msdb;Data Source=10.1.1.50"
Set Cnn = CreateObject("ADODB.Connection")
Cnn.Open strCnn
'查看是否连接成功,成功状态值为1
If Cnn.State = 0 Then
msgbox "连接数据库失败"
wscript.quit
End If
strQuery = "SELECT * from komp_sys..node"
Set rs = Cnn.Execute(strQuery)
If Not rs.BOF Then
Do While Not rs.EOF
For k = 0 To 5 '循环6次
WriteFile.Write ""&rs(k)
WriteFile.Write vbTab
Next
WriteFile.Write vbCrlf
rs.MoveNext
Loop
Else
wscript.echo "没有数据"
End If
Cnn.Close
WriteFile.Close
Set Cnn = Nothing
Set fso = Nothing