Reputation: 4069
I have an ASP.NET application I'm developing. In it is a CR report. When I first wrote the report, I had it hard coded to point to my development server (using MSSQL with Windows integrated login). So, when I moved my app to the production server, it of course failed. I have been searching for an answer on how to connect it to DB listed in the Web.config, but haven't had any luck.
I saw one suggestion that I create a dataset in my project and tie in to that, but now it seems I can't use a parameter to filter the records. I did see one other suggestion on how you can change the DB source on the fly, but that was designed for those who want to change the DB in mid session, rather than dependent on the machine, and seemed overkill.
Does anyone have a nice simple solution? I have been working on this problem for way too long and feel that I'm about to shoot my computer (that will teach it a lesson). :-(
Upvotes: 0
Views: 1539
Reputation: 21684
public static class ReportDocumentExtensions
{
public static void SetConnectionInfo(this ReportDocument report, ReportContextArgs context)
{
SetConnectionInfo(report, context.UserId, context.Password, context.ServerName, context.DatabaseName);
}
public static void SetConnectionInfo(this ReportDocument report, string userId, string password, string serverName, string databaseName)
{
foreach (Table oTable in report.Database.Tables)
{
TableLogOnInfo oInfo = oTable.LogOnInfo;
ConnectionInfo oConnection = oTable.LogOnInfo.ConnectionInfo;
oConnection.UserID = userId;
oConnection.Password = password;
oConnection.ServerName = serverName;
oConnection.DatabaseName = databaseName;
oTable.ApplyLogOnInfo(oInfo);
}
}
}
public class ReportContextArgs
{
private string _userId;
private string _password;
private string _serverName;
private string _databaseName;
public string ServerName
{
get { return _serverName; }
set { _serverName = value; }
}
public string UserId
{
get { return _userId; }
set { _userId = value; }
}
public string Password
{
get { return _password; }
set { _password = value; }
}
public string DatabaseName
{
get { return _databaseName; }
set { _databaseName = value; }
}
}
Upvotes: 2