Public Shared Function Get_Login_Info(ByRef info_required As String) As String
Dim cs As String = ConfigurationManager.ConnectionStrings("DataLink").ConnectionString
Dim Str_ServerName = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim
cs = cs.Substring(cs.IndexOf(";") + 1)
Dim Str_DatabaseName = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim
cs = cs.Substring(cs.IndexOf(";") + 1)
Dim Str_Persist = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim
cs = cs.Substring(cs.IndexOf(";") + 1)
Dim Str_UserID = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim
Dim Str_Password = cs.Substring(cs.IndexOf(";") + 1)
Select Case info_required
Case "Server"
Return Str_ServerName
Case "Database"
Return Str_DatabaseName
Case "User"
Return Str_UserID
Case "Password"
Return Str_Password
End Select
End Function
Public Shared Sub set_table_location(ByRef tables As Tables)
Dim c As New ConnectionInfo
c.ServerName = dataccess.Get_Login_Info("Server")
c.DatabaseName = dataccess.Get_Login_Info("Database")
c.UserID = dataccess.Get_Login_Info("User")
c.Password = dataccess.Get_Login_Info("Password")
For Each t As Table In tables
Dim tableloginfo As TableLogOnInfo = t.LogOnInfo
tableloginfo.ConnectionInfo = c
t.ApplyLogOnInfo(tableloginfo)
Next
End Sub
Then the following in the page load of the report
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim rep As New ReportDocument
rep.Load(report)
dataccess.set_table_location(rep.Database.Tables)
rep.SetDatabaseLogon(dataccess.Get_Login_Info("User"), dataccess.Get_Login_Info("Password"), dataccess.Get_Login_Info("Server"), dataccess.Get_Login_Info("Database"))
rep.SetDataSource(getTreeViewData)
myCrystalReportViewer.ReportSource = rep
rep.VerifyDatabase()
rep.Refresh()
End Sub
Do something out of character each day this week. Change your hairstyle, wear a different colour, show your teeth when you smile, eat chocolate-anything! Just choose to be different because you can!
Means you are still using security info, integrated means it is your windows login. I suggest setup a password and use it as int example above.
Do something out of character each day this week. Change your hairstyle, wear a different colour, show your teeth when you smile, eat chocolate-anything! Just choose to be different because you can!
pdassnyc
Member
221 Points
228 Posts
Re: How can i use connection string from web.config in Crystal reports?
Apr 08, 2010 01:16 PM|LINK
Hi,
No I ended up just adjusting the crystal file itself to point to the production db, the file was not reading the web.config entry at all.
DerickC
Member
63 Points
150 Posts
Re: How can i use connection string from web.config in Crystal reports?
Jan 14, 2011 10:02 AM|LINK
Created the following in a dataccess class
Public Shared Function Get_Login_Info(ByRef info_required As String) As String Dim cs As String = ConfigurationManager.ConnectionStrings("DataLink").ConnectionString Dim Str_ServerName = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim cs = cs.Substring(cs.IndexOf(";") + 1) Dim Str_DatabaseName = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim cs = cs.Substring(cs.IndexOf(";") + 1) Dim Str_Persist = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim cs = cs.Substring(cs.IndexOf(";") + 1) Dim Str_UserID = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim Dim Str_Password = cs.Substring(cs.IndexOf(";") + 1) Select Case info_required Case "Server" Return Str_ServerName Case "Database" Return Str_DatabaseName Case "User" Return Str_UserID Case "Password" Return Str_Password End Select End Function Public Shared Sub set_table_location(ByRef tables As Tables) Dim c As New ConnectionInfo c.ServerName = dataccess.Get_Login_Info("Server") c.DatabaseName = dataccess.Get_Login_Info("Database") c.UserID = dataccess.Get_Login_Info("User") c.Password = dataccess.Get_Login_Info("Password") For Each t As Table In tables Dim tableloginfo As TableLogOnInfo = t.LogOnInfo tableloginfo.ConnectionInfo = c t.ApplyLogOnInfo(tableloginfo) Next End SubThen the following in the page load of the report
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim rep As New ReportDocument rep.Load(report) dataccess.set_table_location(rep.Database.Tables) rep.SetDatabaseLogon(dataccess.Get_Login_Info("User"), dataccess.Get_Login_Info("Password"), dataccess.Get_Login_Info("Server"), dataccess.Get_Login_Info("Database")) rep.SetDataSource(getTreeViewData) myCrystalReportViewer.ReportSource = rep rep.VerifyDatabase() rep.Refresh() End Subhamidaspnet
Member
32 Points
24 Posts
Re: How can i use connection string from web.config in Crystal reports?
Jun 25, 2012 06:42 PM|LINK
Hi.
I use connectio string similar to:
"Data Source=.\SQLEXPRESS;AttachDbFilename='d:\Wares.mdf';Integrated Security=True;User Instance=True"
i dont use username and password, but when crystallReportViewer open , need uid and pass?!!!
DerickC
Member
63 Points
150 Posts
Re: How can i use connection string from web.config in Crystal reports?
Jun 25, 2012 07:04 PM|LINK
Means you are still using security info, integrated means it is your windows login. I suggest setup a password and use it as int example above.
qasims
Member
2 Points
1 Post
Re: How can i use connection string from web.config in Crystal reports?
Jul 04, 2012 01:06 PM|LINK
Need to fix the password line...
var cs = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["TNTConnectionString"].ConnectionString;
var Str_ServerName = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim();
cs = cs.Substring(cs.IndexOf(";") + 1);
var Str_DatabaseName = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim();
cs = cs.Substring(cs.IndexOf(";") + 1);
var Str_Persist = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim();
cs = cs.Substring(cs.IndexOf(";") + 1);
var Str_UserID = (cs.Substring(cs.IndexOf("=") + 1, cs.IndexOf(";") - cs.IndexOf("=") - 1)).Trim();
cs = cs.Substring(cs.IndexOf(";") + 1);
var Str_Password = cs.Substring(cs.IndexOf("=") + 1);
http://codeonlyyours.blogspot.com