vb6下水晶报表10连接sql2000出错
本人接触水晶报表几天,尝试不通过向导,而通过代码让水晶报表读取sql2000中数据库数据,但一直出现错误说logon falied,还有就是ado error code什么的,好像就是登陆失败,可是数据库明明已经连上。程序是参照它给的范例改的。Private Sub cmdADO_Click()
Dim fld As FieldObject
Dim strCnn As String
Set cnn1 = New ADODB.Connection
strCnn = "Provider=MSDASQL;Persist Security Info=False;Data Source=Xtreme Sample Database 10;Mode=Read"
cnn1.Open strCnn
Set datcmd1 = New ADODB.Command
Set datcmd1.ActiveConnection = cnn1
datcmd1.CommandText = "Customer"
datcmd1.CommandType = adCmdTable
m_Report.Database.AddADOCommand cnn1, datcmd1
Set fld = m_Report.Section3.AddFieldObject("{ado.Customer Name}", 0, 0)
LoadReport ’调用子函数
End Sub
以上示范程序正常,但我直接更改连接字符串连接sql2000 不可以吗
strcnn="Provider=SQLOLEDB.1;persist security info=false;user id=sa;Password=sa; initial catalog=master;datasource=." --------------------编程问答-------------------- 下面是我们用调用unix下informix数据库,连接的代码,看看有没有用。cr 版本9
Dim crxTable As CRAXDRT.DatabaseTable
Dim crxReportObject As Object
Dim crxSubReportOject As CRAXDRT.SubreportObject
Dim crxSubReport As CRAXDRT.Report
Dim crxSection As CRAXDRT.Section
Dim strLocation As String
' Do the report
For Each crxTable In crxRpt.Database.Tables
'switch to passed database, instance sever
'use the bill print user's login code and password
crxTable.SetLogOnInfo ServerName, DatabaseName, UnixBillPrintUserName, UnixBillPrintPassword
'see comment in strp function
strLocation = StripDatabaseAndOwner(crxTable.Location)
crxTable.SetTableLocation strLocation, "", ""
Next crxTable
' Link the subforms to the appropraite datasource
For Each crxSection In crxRpt.Sections
For Each crxReportObject In crxSection.ReportObjects
If crxReportObject.Kind = crSubreportObject Then
Set crxSubReportOject = crxReportObject
Set crxSubReport = crxSubReportOject.OpenSubreport
For Each crxTable In crxSubReport.Database.Tables
'switch to passed database, instance sever
crxTable.SetLogOnInfo ServerName, DatabaseName, _
UnixBillPrintUserName, UnixBillPrintPassword
strLocation = StripDatabaseAndOwner(crxTable.Location)
crxTable.SetTableLocation strLocation, "", ""
Next crxTable
End If
Next crxReportObject
Next crxSection
SetDataSource = True
Set crxTable = Nothing
Set crxReportObject = Nothing
Set crxSubReportOject = Nothing
Set crxSubReport = Nothing
Set crxSection = Nothing
补充:VB , 数据库(包含打印,安装,报表)