{"id":733,"date":"2008-01-04T19:56:57","date_gmt":"2008-01-05T02:56:57","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/crystal-reports-xi\/1718-connecting-with-the-reportdocument\/"},"modified":"2008-01-04T19:56:57","modified_gmt":"2008-01-05T02:56:57","slug":"1718-connecting-with-the-reportdocument","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/1718-connecting-with-the-reportdocument\/","title":{"rendered":"17.18 Connecting with the ReportDocument"},"content":{"rendered":"<h2>Logging On with the ReportDocument<\/h2>\n<p>The ReportDocument object has a Tables collection that stores each table in a report. The program loops through each table in this collection and sets the logon properties for it. Listing 17-11 shows how to loop through each data source and set these properties. It sets different login credentials based upon the table.<\/p>\n<p>         <code_Caption>Listing 17-11. Logging in to multiple tables.<\/code_Caption><br \/>\n         <code>Private Sub LoginToTables(ByVal UserId As String, ByVal Password As String)<\/code><br \/>\n         <code>Dim myReport As New CrystalReport1()<\/code><br \/>\n         <code>Dim myTable As CrystalDecisions.CrystalReports.Engine.Table<\/code><br \/>\n         <code>Dim myLogonInfo As CrystalDecisions.Shared.TableLogOnInfo<\/code><br \/>\n         <code>'Changing the logon info<\/code><br \/>\n         <code>For Each myTable In myReport.Database.Tables<\/code><br \/>\n         <code>myLogonInfo = myTable.LogOnInfo<\/code><br \/>\n         <code>If myTable.Name = \" CorpStandards\" Then<\/code><br \/>\n         <code>With myLogonInfo.ConnectionInfo<\/code><br \/>\n         <code>.UserID = G_UserId<\/code><br \/>\n         <code>.Password = G_Password<\/code><br \/>\n         <code>End With<\/code><br \/>\n         <code>Else<\/code><br \/>\n         <code>With myLogonInfo.ConnectionInfo<\/code><br \/>\n         <code>.UserID = UserId<\/code><br \/>\n         <code>.Password = Password<\/code><br \/>\n         <code>End With<\/code><br \/>\n         <code>End If<\/code><br \/>\n         <code>myTable.ApplyLogOnInfo(myLogonInfo)<\/code><br \/>\n         <code>'Test if the user credentials are valid<\/code><br \/>\n         <code>If Not myTable.TestConnectivity() Then<\/code><br \/>\n         <code>MessageBox.Show(\"Invalid user credentials for table: \" &amp; myTable.Name)<\/code><br \/>\n         <code>End If<\/code><br \/>\n         <code>Next myTable<\/code><br \/>\n         <code>CrystalReportViewer1.ReportSource = myReport<\/code><br \/>\n         <code>End Sub<\/code><\/p>\n<p>To example illustrates how each table is treated separately. It uses a table called CorpStandards that has public access for everyone in the company. It uses a global user account to login to it. All other tables have specific security and use the current user&#8217;s login information. This is managed elsewhere in the program and is passed to this procedure via its parameter list.<\/p>\n<p>The code loops through each table in the ReportDocument.Database. Tables collection and gets a reference to the TableLogOnInfo object. If the table name is &#8220;CorpStandards&#8221; it applies the generic login information. For all other tables it uses the login parameters passed to the procedure. After setting the properties, it calls the ApplyLogOnInfo() method of the Table class. This updates the table with the new login properties. The TestConnectivity() method is used to determine whether the user credentials are valid or not. If they aren&#8217;t then a message box is displayed that tells which table failed. The report viewer is assigned the report document and this forces the report to open the database connections using the user credentials and display the report.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Logging On with the ReportDocument The ReportDocument object has a Tables collection that stores each table in a report. The program loops through each table in this collection and sets the logon properties for it. Listing 17-11 shows how to loop through each data source and set these properties. It sets different login credentials based [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,2],"tags":[],"class_list":["post-733","post","type-post","status-publish","format-standard","hentry","category-chapter-17-dynamic-data-sources","category-crystal-reportsnet-2003","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=733"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/733\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=733"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}