Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Challenging Crystal Reports / .NET Windows application question

Challenging Crystal Reports / .NET Windows application question

Scheduled Pinned Locked Moved Visual Basic
databasequestioncsharpsql-server
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KreativeKai
    wrote on last edited by
    #1

    I have a VB.NET VS2008 windows form application where I have a crystalviewer form setup to print a few reports out from the menu off of the main data entry form. The crystal reports are already written and stored in a folder on one of our servers (For this example lets call it \\MyServer\ReportFolder\). The crystal report uses a DSN to know where to find the data (For this example lets call it MyCrystalDSN). The code on the menu fires off the report as shown below: Dim frmCV As New frmCrystalViewer frmCV.CrystalReportViewer1.ReportSource = "\\MyServer\ReportFolder\Reportname.rpt" frmCV.WindowState = FormWindowState.Maximized frmCV.ShowDialog() Ok, everything works great for now, but of course it never fails that when you develop at your desk with all the rights available as a developer it all works and when you deploy the app, everything never works as planned. When I publish the project for use by the client, I have to setup a DSN so the Crystal Reports will work. Can I do this on the fly with code? For example, my crystal reports are using the MyCrystalDSN, and I don't want to have to remember to setup a DSN for everyone's computer I deploy the application on. Can I code the DSN information to use in the code prior to firing off the report? A coworker gave me the following code from an article that I believe was written in 2001 for VB6. Is anyone doing this in .NET? Here is that code: Public Sub RegisterDatabaseSample() 'Create a DSN called TEST on a server called ThatServer DBEngine.RegisterDatabase "TEST", "SQL Server", True, _ "Database=pubs" & _ vbCr & "Description=Sample DSN" & _ vbCr & "Server=ThatServer" End Sub Any help is appreciated :)

    Lost in the vast sea of .NET

    K C 2 Replies Last reply
    0
    • K KreativeKai

      I have a VB.NET VS2008 windows form application where I have a crystalviewer form setup to print a few reports out from the menu off of the main data entry form. The crystal reports are already written and stored in a folder on one of our servers (For this example lets call it \\MyServer\ReportFolder\). The crystal report uses a DSN to know where to find the data (For this example lets call it MyCrystalDSN). The code on the menu fires off the report as shown below: Dim frmCV As New frmCrystalViewer frmCV.CrystalReportViewer1.ReportSource = "\\MyServer\ReportFolder\Reportname.rpt" frmCV.WindowState = FormWindowState.Maximized frmCV.ShowDialog() Ok, everything works great for now, but of course it never fails that when you develop at your desk with all the rights available as a developer it all works and when you deploy the app, everything never works as planned. When I publish the project for use by the client, I have to setup a DSN so the Crystal Reports will work. Can I do this on the fly with code? For example, my crystal reports are using the MyCrystalDSN, and I don't want to have to remember to setup a DSN for everyone's computer I deploy the application on. Can I code the DSN information to use in the code prior to firing off the report? A coworker gave me the following code from an article that I believe was written in 2001 for VB6. Is anyone doing this in .NET? Here is that code: Public Sub RegisterDatabaseSample() 'Create a DSN called TEST on a server called ThatServer DBEngine.RegisterDatabase "TEST", "SQL Server", True, _ "Database=pubs" & _ vbCr & "Description=Sample DSN" & _ vbCr & "Server=ThatServer" End Sub Any help is appreciated :)

      Lost in the vast sea of .NET

      K Offline
      K Offline
      KreativeKai
      wrote on last edited by
      #2

      I've been searching for the solution on the web and found a few different suggestions which I combined and came up with the answer to my question. Here is the code: Public Declare Auto Function SQLConfigDataSource Lib "ODBCCP32.DLL" _ (ByVal hwndParent As Integer, ByVal fRequest As Integer, _ ByVal lpszDriver As String, ByVal lpszAttributes As String) As Integer Private Const ODBC_ADD_SYS_DSN As Integer = 4 Private Sub Create_DSN_For_Crystal_Reports() Try Dim attributes As New System.Text.StringBuilder() Dim returnCode As Integer attributes.Append("DSN=MyCrystalDSN") attributes.Append(Chr(0)) attributes.Append("Server=MyDBServer") attributes.Append(Chr(0)) attributes.Append("Description=DSN added via code from My VB App") attributes.Append(Chr(0)) attributes.Append("Database=MyDatabase") attributes.Append(Chr(0)) attributes.Append("AnsiNPW=Yes") attributes.Append(Chr(0)) attributes.Append("QuotedId=Yes") attributes.Append(Chr(0)) attributes.Append("Trusted_Connection=Yes") attributes.Append(Chr(0)) attributes.Append(Chr(0)) returnCode = SQLConfigDataSource(0&;, ODBC_ADD_SYS_DSN, "SQL Server", attributes.ToString) If returnCode <> 1 Then Throw New Exception("DSN could not be setup to allow Crystal Reports access") End If Catch ex as Exception msgbox(ex.message) End Try End Sub Hopefully posting the answer will help someone else later who has the same problem. :-D

      Lost in the vast sea of .NET

      modified on Thursday, March 6, 2008 8:45 AM

      1 Reply Last reply
      0
      • K KreativeKai

        I have a VB.NET VS2008 windows form application where I have a crystalviewer form setup to print a few reports out from the menu off of the main data entry form. The crystal reports are already written and stored in a folder on one of our servers (For this example lets call it \\MyServer\ReportFolder\). The crystal report uses a DSN to know where to find the data (For this example lets call it MyCrystalDSN). The code on the menu fires off the report as shown below: Dim frmCV As New frmCrystalViewer frmCV.CrystalReportViewer1.ReportSource = "\\MyServer\ReportFolder\Reportname.rpt" frmCV.WindowState = FormWindowState.Maximized frmCV.ShowDialog() Ok, everything works great for now, but of course it never fails that when you develop at your desk with all the rights available as a developer it all works and when you deploy the app, everything never works as planned. When I publish the project for use by the client, I have to setup a DSN so the Crystal Reports will work. Can I do this on the fly with code? For example, my crystal reports are using the MyCrystalDSN, and I don't want to have to remember to setup a DSN for everyone's computer I deploy the application on. Can I code the DSN information to use in the code prior to firing off the report? A coworker gave me the following code from an article that I believe was written in 2001 for VB6. Is anyone doing this in .NET? Here is that code: Public Sub RegisterDatabaseSample() 'Create a DSN called TEST on a server called ThatServer DBEngine.RegisterDatabase "TEST", "SQL Server", True, _ "Database=pubs" & _ vbCr & "Description=Sample DSN" & _ vbCr & "Server=ThatServer" End Sub Any help is appreciated :)

        Lost in the vast sea of .NET

        C Offline
        C Offline
        codemunch
        wrote on last edited by
        #3

        You can create a typed dataset, get the data yourself via ADO.net and then supply the report with the loaded type dataset and then you don't need a DSN for Crystal. A developer I work with has used this technique in the past. I haven't tried it yet. http://support.microsoft.com/kb/320714 http://www.gridviewguy.com/ArticleDetails.aspx?articleID=201\_Creating\_Crystal\_Reports\_Using\_Typed\_DataSet

        K 1 Reply Last reply
        0
        • C codemunch

          You can create a typed dataset, get the data yourself via ADO.net and then supply the report with the loaded type dataset and then you don't need a DSN for Crystal. A developer I work with has used this technique in the past. I haven't tried it yet. http://support.microsoft.com/kb/320714 http://www.gridviewguy.com/ArticleDetails.aspx?articleID=201\_Creating\_Crystal\_Reports\_Using\_Typed\_DataSet

          K Offline
          K Offline
          KreativeKai
          wrote on last edited by
          #4

          Thanks for the feedback. I'm actually using the technique you suggested in several other projects and yes it works great. With the project I'm currently working on, they want me to fire off already created Crystal Reports from my VB application which uses a preset DSN. Thanks again for you response! :-D

          Lost in the vast sea of .NET

          C 1 Reply Last reply
          0
          • K KreativeKai

            Thanks for the feedback. I'm actually using the technique you suggested in several other projects and yes it works great. With the project I'm currently working on, they want me to fire off already created Crystal Reports from my VB application which uses a preset DSN. Thanks again for you response! :-D

            Lost in the vast sea of .NET

            C Offline
            C Offline
            codemunch
            wrote on last edited by
            #5

            Oh I see - yeah, that's too bad - that's our current situation too - forced to use the DSN way due to the reports being developed that way. I'm too lazy to look into it, but perhaps with the Developer edition of CR someone could modify the data source part on the fly and convert it to accept data through a typed set instead of DSN's.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups