|M| 水晶报表打印问题:无法连接:错误的登录参数。 刚才可以的但现在总是报这个错

zyciis351 2007-07-27 11:17:49
文件 C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\myReport {470FACA3-F0B9-47E0-B82B-5AC54001D28E}.rpt 内出错:
无法连接:错误的登录参数。
代码:
string strPrinterName;
strPrinterName = new PrintDocument().PrinterSettings.PrinterName;
ReportDocument doc = new ReportDocument();
doc.Load(Server.MapPath("myReport.rpt"));
doc.SetDataSource(ds);
//应用打印机名称
doc.PrintOptions.PrinterName = strPrinterName;
// 打印 // 打印报柄剑将 startPageN 和 endPageN
// 参数设置为 0 柄婢打印所有页。
doc.PrintToPrinter(1, false, 0, 0);
doc.Dispose();
...全文
1387 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
baobingbing 2010-02-03
  • 打赏
  • 举报
回复
高手是找不着了。。。咱自己摸吧。。
bbg 2007-10-31
  • 打赏
  • 举报
回复
我也遇到这个问题,看来是一个常见问题,强烈请求高手出马点拨!!!
bote_china 2007-07-31
  • 打赏
  • 举报
回复
这个应该不是登录信息的问题,应该是数据源与设计报表时指定的数据源不符,报表加载时无法从指定数据源中获取数据,所以会报登录信息不正确的错误
yyj135 2007-07-31
  • 打赏
  • 举报
回复
你的报表没有设置登录参数。
你需要把服务器名、数据库名、用户名、密码传递给报表。否则会提示这个错误。
我这里有一段VB.NET的,你自己看一下应该明白的:
Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint
'新建一個表單
Dim Frm As New Frm_Wating

Try
Me.Cursor = Cursors.WaitCursor

Dim Num, strRPTFile, str() As String
Dim srv, db, user, pwd As String
Dim sql As String
Dim dsSub As New DataSet

Dim sqlConn As New SqlConnection


If Me.dgv1.DataSource Is Nothing Then
Exit Function
End If

If Me.dgv1.SelectedCells.Count <= 0 Then
Exit Function

End If

If Me.dgv1.CurrentCell Is Nothing Then
Exit Function
End If

Num = Me.dgv1.Rows(Me.dgv1.CurrentRow.Index).Cells("Num").Value
If Num Is Nothing Then
Exit Function
Else

Frm.Show()

str = ReadConfigFile.Split(";")


strRPTFile = GetReportPath("PUR", "PUR_PO.rpt")

For I As Integer = 0 To str.Length - 1
If str(I).IndexOf("=") > 0 Then
If str(I).Split("=")(0).ToUpper = "Server".ToUpper Then
srv = str(I).Split("=")(1)
End If

If str(I).Split("=")(0).ToUpper = "DataBase".ToUpper Then
db = str(I).Split("=")(1)
End If

If str(I).Split("=")(0).ToUpper = "Uid".ToUpper Then
user = str(I).Split("=")(1)
End If

If str(I).Split("=")(0).ToUpper = "Pwd".ToUpper Or str(I).Split("=")(0).ToUpper = "Password".ToUpper Then
pwd = str(I).Split("=")(1)
End If

End If
Next

Dim CMD As System.Data.SqlClient.SqlCommand
Dim sqlAD As New SqlDataAdapter
Dim ds As New DataSet



Dim myReportDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim myParameterValues As New CrystalDecisions.Shared.ParameterValues
Dim myDiscreteValue As New CrystalDecisions.Shared.ParameterDiscreteValue


strRPTFile = GetReportPath("PUR", "PUR_PO.rpt")

sqlConn.ConnectionString = ConfigurationManager.AppSettings("SqlServer")
If sqlConn.State = ConnectionState.Closed Then
sqlConn.Open()
End If


CMD = New SqlClient.SqlCommand("Select_PO", sqlConn)
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandTimeout = 60

CMD.Parameters.Add(New SqlClient.SqlParameter("@Num", SqlDbType.NVarChar, 4000))
CMD.Parameters("@Num").Value = Num


CMD.ExecuteNonQuery()
CMD.Dispose()

sqlAD.SelectCommand = CMD
sqlAD.Fill(ds, "Rptds")


'向子報表傳遞參數
sql = "exec dbo.GetCommpanyInfo"
dsSub = ReturnDataset(sql)


Dim logonInfo As New TableLogOnInfo
Dim table As Table
myReportDoc.Load(strRPTFile)


'设置登录信息
For Each table In myReportDoc.Database.Tables
logonInfo = table.LogOnInfo
With logonInfo.ConnectionInfo
.ServerName = srv
.DatabaseName = db
.UserID = user
.Password = pwd
End With
table.ApplyLogOnInfo(logonInfo)

Next




'向子報表傳遞登錄參數
For I As Integer = 0 To myReportDoc.Subreports.Count - 1

For Each table In myReportDoc.Subreports(I).Database.Tables
With logonInfo.ConnectionInfo
.ServerName = srv
.DatabaseName = db
.UserID = user
.Password = pwd
End With
table.ApplyLogOnInfo(logonInfo)
Next

If myReportDoc.Subreports(I).Name = "CommpanyInfo" Then
myReportDoc.Subreports(I).SetDataSource(dsSub.Tables(0))

End If

Next

myReportDoc.SetDataSource(ds.Tables(0))


My.Forms.Frm_Report.CrystalReportViewer1.ReportSource = myReportDoc
My.Forms.Frm_Report.CrystalReportViewer1.Zoom(1)
My.Forms.Frm_Report.CrystalReportViewer1.DisplayGroupTree = False

Frm.Dispose()

Frm_Report.ShowDialog()



End If


Catch ex As Exception
Me.Cursor = Cursors.Default
MsgBox(ex.Message, MsgBoxStyle.Exclamation, Msg.CompanyName)
Finally
Frm = Nothing
Me.Cursor = Cursors.Default
End Try
End Function
vainnetwork 2007-07-28
  • 打赏
  • 举报
回复
关注,帮顶
zyciis351 2007-07-27
  • 打赏
  • 举报
回复
doc.PrintToPrinter(1, false, 0, 0);这一句出错

4,819

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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