Search code examples
c#sql-server-2008crystal-reportsdatabase-connection

Database Login required when generating Crytal Report. SQL Server 08, VS 08


When o load my Crystal Report onto a CrystalReportViewer i am prompted with Database Login with disabled (fixed) server name.

Now when i load the same report on my development machine, it works fine. but when i deploy the C# application on a different machine, i am always prompted for a DB Login. (where the server-name is the one used on my development machine and its static (i cant change it)

i have been trying to find a solution for weeks now and with no luck.

i am using a DataTable as a report source :

MyReport.SetDataSource(MyDataTable)

i have tried most of the online solutions that i searched for.

i have tried passing the DB Login information at run-time

i have installed the SQL Native Client

i have tried to pass a DataSet instead of a DataTable

All with no luck

it also came to my understanding that when i load a report with 1 database table inside i am not prompted for database login (i.e. my datable will be filled with one table form the database : "Select * From SomeTable" when i use an inner join query i am prompted for the login

Any thoughts anyone on how to handle this issue.


Solution

  • well i have finally solved it i was using

    cr.SetDatabaseLogon(Username, Password, @Server, DBNAME);
    

    i replaced that code and passed the login information for each table used in the report

    T

    ableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
                    TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
                    ConnectionInfo CInfo = new ConnectionInfo();
                    //GET THE SERVER INFORMATION
                    DataTable DT = b.GetServerInfo();
                    CInfo.ServerName = DT.Rows[0][1].ToString();
                    CInfo.DatabaseName = DT.Rows[0][2].ToString();
                    CInfo.UserID = DT.Rows[0][3].ToString();
                    CInfo.Password = DT.Rows[0][4].ToString();
                    Tables CrTables = cr.Database.Tables;
                    foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                    {
                        crtableLogoninfo = CrTable.LogOnInfo;
                        crtableLogoninfo.ConnectionInfo = CInfo;
                        CrTable.ApplyLogOnInfo(crtableLogoninfo);
                    }
    
    
                    frmReportViewer ff = new frmReportViewer();
                    ff.crViewer.LogOnInfo = crtableLogoninfos;
                    ff.crViewer.ReportSource = cr;