I'm using the Crystal Report 9.0 version shipped in VS.NET to create my reports...in the designer I design my report and access my database, where I create my connection with userid/password...The problem is that when I run my report from within my app, a screen pops up for userid/password...anyone know how I can make it go away!
One quick way will be this:
Imagine your report is called testcr and your viewer is called CRV:
VB Code:
Dim rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim tbl As CrystalDecisions.CrystalReports.Engine.Table
rpt = New testcr()
For Each tbl In rpt.Database.Tables
Dim tbllogin As New CrystalDecisions.Shared.TableLogOnInfo()
tbllogin.ConnectionInfo.UserID = "admin"
tbllogin.ConnectionInfo.Password = "eyetalion"
tbl.ApplyLogOnInfo(tbllogin)
Next
CRV.ReportSource = rpt
Note that if you set password for Access database (at database level, not user-level security), the user ID will be "admin".
You may use it in a more complete way as follows, which is specially useful if you are connecting to a SQL Server.:
VB Code:
For Each tbl In rpt.Database.Tables
Dim coninfo As New CrystalDecisions.Shared.ConnectionInfo()
Dim tbllogin As New CrystalDecisions.Shared.TableLogOnInfo()
coninfo.Password = "mypassword"
coninfo.UserID = "myuser"
coninfo.ServerName = "myserver"
coninfo.DatabaseName = "mydatabse"
tbllogin.ConnectionInfo = coninfo
tbl.ApplyLogOnInfo(tbllogin)
Next
However its not safe to hard code your password as clear text into your code as it is easily readable from your exe file, so you may try to obfuscate it or use some kind of encryption decryption in your code. Also its too easy to recover Access password, so you may not bother yourself with that and as some say best security is physical security.
Attached you will find a working example of the above. Note that I have not set the CRV report source at desgin time, unlike the previous example i sent.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
thanks heaps for the download. i now have my app running a report over a PWd db with parameters.
one last question. what if the locaction of the mdb changes? if i move my mdb from folder X to folder Y then i get this message popup in my code:
Any ideas?
Thanks
"The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.
Windows & Web Developer Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
Sutherland Shire, Sydney Australia www.stingrae.com.au Developer of Arnold - Gym & Martial Arts Database Management System www.gymdatabase.com.au