Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Retrieving the connection string from web.confi

Retrieving the connection string from web.confi

Scheduled Pinned Locked Moved ASP.NET
csharpquestiondatabasehelptutorial
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vempatiprasad
    wrote on last edited by
    #1

    I need help!! I am working on a .NET project using C# with SQLServer as database. I have 10users who access the web site with different user id and password. Each user is having seperate database. Based on each user id, i have to retrieve different connection string from web.config. The same connection string will be used in each page, i access the database. My question is.. how to retrieve the userid in each page? so that I can use it to retrieve the connection string in each page rightnow I am retrieving the userid in login page and form authenticating with database. public void LoginUser(Object s, EventArgs e) { bool blnAuthenticate = Authenticate(username.Text, password.Text); if (username.Text == "AB....") { connString = WebConfigurationManager.ConnectionStrings["ABConnectionInfo"].ToString(); } else if (username.Text == "CD....") { connString = WebConfigurationManager.ConnectionStrings["CDConnectionInfo"].ToString(); } else if (username.Text == "EF....") { connString = WebConfigurationManager.ConnectionStrings["EFConnectionInfo"].ToString(); } else if (username.Text == "GH..") { connString = WebConfigurationManager.ConnectionStrings["GHConnectionInfo"].ToString(); } else if (username.Text == "IJ....") { connString = WebConfigurationManager.ConnectionStrings["IJConnectionInfo"].ToString(); } if (blnAuthenticate) { FormsAuthentication.RedirectFromLoginPage(username.Text, false); } else { lblError.Text = "Your login was invalid. Please try again."; } } bool Authenticate(string strUsername, string strPassword) { ............ } I appreciate help from anybody..Thank you

    M P K 3 Replies Last reply
    0
    • V vempatiprasad

      I need help!! I am working on a .NET project using C# with SQLServer as database. I have 10users who access the web site with different user id and password. Each user is having seperate database. Based on each user id, i have to retrieve different connection string from web.config. The same connection string will be used in each page, i access the database. My question is.. how to retrieve the userid in each page? so that I can use it to retrieve the connection string in each page rightnow I am retrieving the userid in login page and form authenticating with database. public void LoginUser(Object s, EventArgs e) { bool blnAuthenticate = Authenticate(username.Text, password.Text); if (username.Text == "AB....") { connString = WebConfigurationManager.ConnectionStrings["ABConnectionInfo"].ToString(); } else if (username.Text == "CD....") { connString = WebConfigurationManager.ConnectionStrings["CDConnectionInfo"].ToString(); } else if (username.Text == "EF....") { connString = WebConfigurationManager.ConnectionStrings["EFConnectionInfo"].ToString(); } else if (username.Text == "GH..") { connString = WebConfigurationManager.ConnectionStrings["GHConnectionInfo"].ToString(); } else if (username.Text == "IJ....") { connString = WebConfigurationManager.ConnectionStrings["IJConnectionInfo"].ToString(); } if (blnAuthenticate) { FormsAuthentication.RedirectFromLoginPage(username.Text, false); } else { lblError.Text = "Your login was invalid. Please try again."; } } bool Authenticate(string strUsername, string strPassword) { ............ } I appreciate help from anybody..Thank you

      M Offline
      M Offline
      MHASSANF
      wrote on last edited by
      #2

      you can add your connectionstring or userid to session at login page and use the session in another pages

      MHFARDAD

      V 1 Reply Last reply
      0
      • V vempatiprasad

        I need help!! I am working on a .NET project using C# with SQLServer as database. I have 10users who access the web site with different user id and password. Each user is having seperate database. Based on each user id, i have to retrieve different connection string from web.config. The same connection string will be used in each page, i access the database. My question is.. how to retrieve the userid in each page? so that I can use it to retrieve the connection string in each page rightnow I am retrieving the userid in login page and form authenticating with database. public void LoginUser(Object s, EventArgs e) { bool blnAuthenticate = Authenticate(username.Text, password.Text); if (username.Text == "AB....") { connString = WebConfigurationManager.ConnectionStrings["ABConnectionInfo"].ToString(); } else if (username.Text == "CD....") { connString = WebConfigurationManager.ConnectionStrings["CDConnectionInfo"].ToString(); } else if (username.Text == "EF....") { connString = WebConfigurationManager.ConnectionStrings["EFConnectionInfo"].ToString(); } else if (username.Text == "GH..") { connString = WebConfigurationManager.ConnectionStrings["GHConnectionInfo"].ToString(); } else if (username.Text == "IJ....") { connString = WebConfigurationManager.ConnectionStrings["IJConnectionInfo"].ToString(); } if (blnAuthenticate) { FormsAuthentication.RedirectFromLoginPage(username.Text, false); } else { lblError.Text = "Your login was invalid. Please try again."; } } bool Authenticate(string strUsername, string strPassword) { ............ } I appreciate help from anybody..Thank you

        P Offline
        P Offline
        Palash Biswas
        wrote on last edited by
        #3

        If you don;t want to use Session object then declare a Static hash table and put all the Connection string when you get it and retrieve it through out the page

        N V 2 Replies Last reply
        0
        • P Palash Biswas

          If you don;t want to use Session object then declare a Static hash table and put all the Connection string when you get it and retrieve it through out the page

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          And how will this improve things? What happens when a connection string is updated in the webconfig?


          I know the language. I've read a book. - _Madmatt

          1 Reply Last reply
          0
          • V vempatiprasad

            I need help!! I am working on a .NET project using C# with SQLServer as database. I have 10users who access the web site with different user id and password. Each user is having seperate database. Based on each user id, i have to retrieve different connection string from web.config. The same connection string will be used in each page, i access the database. My question is.. how to retrieve the userid in each page? so that I can use it to retrieve the connection string in each page rightnow I am retrieving the userid in login page and form authenticating with database. public void LoginUser(Object s, EventArgs e) { bool blnAuthenticate = Authenticate(username.Text, password.Text); if (username.Text == "AB....") { connString = WebConfigurationManager.ConnectionStrings["ABConnectionInfo"].ToString(); } else if (username.Text == "CD....") { connString = WebConfigurationManager.ConnectionStrings["CDConnectionInfo"].ToString(); } else if (username.Text == "EF....") { connString = WebConfigurationManager.ConnectionStrings["EFConnectionInfo"].ToString(); } else if (username.Text == "GH..") { connString = WebConfigurationManager.ConnectionStrings["GHConnectionInfo"].ToString(); } else if (username.Text == "IJ....") { connString = WebConfigurationManager.ConnectionStrings["IJConnectionInfo"].ToString(); } if (blnAuthenticate) { FormsAuthentication.RedirectFromLoginPage(username.Text, false); } else { lblError.Text = "Your login was invalid. Please try again."; } } bool Authenticate(string strUsername, string strPassword) { ............ } I appreciate help from anybody..Thank you

            K Offline
            K Offline
            Krunal Berawala
            wrote on last edited by
            #5

            you can use the following code........in C#.net either put your connection string in web.config under appsettings/connections string section using System.Configuration; public static string ConnectionString { get { //return ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); return ConfigurationManager.AppSettings["ConnectionString"].ToString(); } }

            N 1 Reply Last reply
            0
            • K Krunal Berawala

              you can use the following code........in C#.net either put your connection string in web.config under appsettings/connections string section using System.Configuration; public static string ConnectionString { get { //return ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); return ConfigurationManager.AppSettings["ConnectionString"].ToString(); } }

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              Did even bother to read the original post?


              I know the language. I've read a book. - _Madmatt

              1 Reply Last reply
              0
              • M MHASSANF

                you can add your connectionstring or userid to session at login page and use the session in another pages

                MHFARDAD

                V Offline
                V Offline
                vempatiprasad
                wrote on last edited by
                #7

                Thanx Hussain. As you said, i used Session variable to get the connectionstring.

                1 Reply Last reply
                0
                • P Palash Biswas

                  If you don;t want to use Session object then declare a Static hash table and put all the Connection string when you get it and retrieve it through out the page

                  V Offline
                  V Offline
                  vempatiprasad
                  wrote on last edited by
                  #8

                  Thanx Mr.Biswas. I did fix the problem with session object. But I will keep in my mind your suggesiton and I will use it in the other module. Thank you Prasad

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups