locked
Retrieving details from the web.config to fill up the details of the db login RRS feed

  • Question

  • User2101954126 posted

    I have successfully viewed my crystal report without prompt of the databse login. In my web.config file, i have this connectionString detail:

     <add name="ConnectionString" connectionString="Data Source=myServer;Initial Catalog=myDatabase;Persist Security Info=True;User ID=kieboy;Password=letMeIn" providerName="Provider=System.Data.SqlClient" />

     Now in my .aspx.cs page (where the crystal report viewer is attached) i have this following code:

    ConnectionInfo myDBConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
    myDBConnectionInfo.ServerName = "myServer";
    myDBConnectionInfo.DatabaseName = "myDatabase";
    myDBConnectionInfo.UserID = "kieboy";
    myDBConnectionInfo.Password = "letMeIn";

     As you can see, I 'manually' typed the login details in the code. Can u guys teach me how to dynamically retrieve the details from the web.config file so that I dont have to change the details in every page when I do decide to change the server names but instead, only change the one in the web.config file, thanks.
     

    Tuesday, March 13, 2007 9:25 AM

All replies

  • User1828997928 posted

    string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];

    will

    Tuesday, March 13, 2007 10:56 AM
  • User1828997928 posted

    string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];

    will

    give
    Tuesday, March 13, 2007 10:56 AM
  • User1828997928 posted

    string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];

    will

    Tuesday, March 13, 2007 10:56 AM
  • User1828997928 posted

    string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];

    will

    Tuesday, March 13, 2007 10:56 AM
  • User1828997928 posted

    string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];

     

    will

    Tuesday, March 13, 2007 10:56 AM
  • User1828997928 posted

    string connectionString = ConfigurationSettings.AppSettings["ConnectionString"];

    Tuesday, March 13, 2007 10:56 AM
  • User2101954126 posted
    Err...still not sure what you want to tell me here. Was hoping you can show me the codes for it. Thanks.
    Tuesday, March 13, 2007 11:37 PM
  • User2101954126 posted
    any help on this?
    Thursday, March 15, 2007 3:47 AM
  • User2101954126 posted

    Nvm, I just added some more connection strings in the web.config like this

    <add name="serverName" connectionString="myServer" />
    <add name="dbName" connectionString="myDatabase" />
    <add name="dbLogin" connectionString="kieboy" />
    <add name="dbPassword" connectionString="letMeIn" />

     then use it for the login details in the codebehind

    ConnectionInfo myDBConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
    myDBConnectionInfo.ServerName = ConfigurationManager.ConnectionStrings["serverName"].ConnectionString;
    myDBConnectionInfo.DatabaseName = ConfigurationManager.ConnectionStrings["dbName"].ConnectionString;
    myDBConnectionInfo.UserID = ConfigurationManager.ConnectionStrings["dbLogin"].ConnectionString;
    myDBConnectionInfo.Password = ConfigurationManager.ConnectionStrings["dbPassword"].ConnectionString;
     

    Thursday, March 15, 2007 4:12 AM
  • User2101954126 posted

    Nvm, I just added some more connection strings in the web.config like this

    <add name="serverName" connectionString="myServer" />
    <add name="dbName" connectionString="myDatabase" />
    <add name="dbLogin" connectionString="kieboy" />
    <add name="dbPassword" connectionString="letMeIn" />

     then use it for the login details in the codebehind

    ConnectionInfo myDBConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
    myDBConnectionInfo.ServerName = ConfigurationManager.ConnectionStrings["serverName"].ConnectionString;
    myDBConnectionInfo.DatabaseName = ConfigurationManager.ConnectionStrings["dbName"].ConnectionString;
    myDBConnectionInfo.UserID = ConfigurationManager.ConnectionStrings["dbLogin"].ConnectionString;
    myDBConnectionInfo.Password = ConfigurationManager.ConnectionStrings["dbPassword"].ConnectionString;
     

    Thursday, March 15, 2007 4:15 AM
  • User2101954126 posted

    Nvm, I just added some more connection strings in the web.config like this

    <add name="serverName" connectionString="myServer" />
    <add name="dbName" connectionString="myDatabase" />
    <add name="dbLogin" connectionString="kieboy" />
    <add name="dbPassword" connectionString="letMeIn" />

     then use it for the login details in the codebehind

    ConnectionInfo myDBConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
    myDBConnectionInfo.ServerName = ConfigurationManager.ConnectionStrings["serverName"].ConnectionString;
    myDBConnectionInfo.DatabaseName = ConfigurationManager.ConnectionStrings["dbName"].ConnectionString;
    myDBConnectionInfo.UserID = ConfigurationManager.ConnectionStrings["dbLogin"].ConnectionString;
    myDBConnectionInfo.Password = ConfigurationManager.ConnectionStrings["dbPassword"].ConnectionString;
     

    Thursday, March 15, 2007 4:44 AM
  • User1828997928 posted

    That will work.  I'm sure there is a way to add the entire connection string at once.  I don't have Crystal on my computer but I think I remember it looking something like this

    ConnectionInfo myDBConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo("entire connection string");

    But what you have will work just fine.

    Thursday, March 15, 2007 9:07 AM