我有一个使用crystal report 8.5和sql server 2005的vb6应用程序。我的问题是,当我打印报告时,我的服务器尚未打开。这是我在vb中的代码:
Option Explicit
Dim ctr As Integer
Dim cn As New ADODB.Connection--Provider=SQLOLEDB.1;Password=password;Persist Security Info=True;User ID=user ID;Initial Catalog=database Name;Data Source=server Name
Dim crApp As CRAXDRT.Application
Dim crReport As CRAXDRT.Report
Dim crtable As CRAXDRT.DatabaseTable
Private Sub prin_Click()
Dim rs As New ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = MDI1.txtado
cn.Open
Set rs = New ADODB.Recordset
rs.Open "select * from temp_abs_yes", cn, adOpenKeyset, adLockOptimistic
Set crApp = New CRAXDRT.Application
Set crReport = crApp.OpenReport("C:\Users\user1.dom\Desktop\ANP\abs_yes.rpt")
crReport.Database.Tables.Item(1).SetLogOnInfo "servername", "databasename", "user", "password"
crReport.Database.Tables.Item(1).SetDataSource rs, 3
crReport.DiscardSavedData
Viewer.ReportSource = crReport
Viewer.ViewReport
rs.close
Set rs = Nothing
Set crReport = Nothing
Set crApp = Nothing
End Sub
答案 0 :(得分:0)
我认为在这种情况下做“SetLogOnInfo”是不必要的,因为你要将数据分配给报告
可能不是你的情况,而是为了别人的帮助。
当我错误地分配servername参数时,我收到了该错误。
我用于登录的正确参数(对于oracle DB):
[...]项目(1).SetLogOnInfo“ [tnsnames] ”,“”,“ [db user] ”,“ [db密码] 强>“
答案 1 :(得分:0)