locked
access connection string from app_code folder in 3.5 update panel of gridview RRS feed

  • Question

  • User1108356276 posted

    hi guys..

    i am making an application in which i have stored connection string in security.cs file under app_code folder...

    all is my application is going well except update panel of gridview using sql datasouce..

    i dont know what to write in connection string .. i mean i have connection string in class file.. 

    so what to write in aspx page so that it will get the connection string from app_code ...

    hope u understand what i am saying..


    i mean to say that 

     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:abc %>" 
                                    SelectCommand="select ID,Author from book_master where author is not null order by author">
                                </asp:SqlDataSource>
    i mean how to write connection string from cs file instead of "abc"



    Tuesday, January 25, 2011 12:45 AM

All replies

  • User1854529396 posted

    Hello

    why you write connection string in sepearte calss file you just add in WEb.config file is enough

    this is format

    <connectionStrings>
    <add name="ConnectionString1" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dbname;User ID=sa;Password=urpwd" providerName="System.Data.SqlClient" />
    </connectionStrings>


    this ll be in code behind

     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1%>"
    SelectCommand="select ID,Author from book_master where author is not null order by author"> </asp:SqlDataSource>


    thanks


    Tuesday, January 25, 2011 3:09 AM
  • User1108356276 posted

    i can not store connection string in web.config cause i have 2-3 database in my app_data folder...user select database from login screen...


    so i put the connection string in app_code folder ....

    public class security
    {
        public class icon 
        {
            //Login
            public string connection(string session)
            {
                string con = "";
                if (session == "2006")
                {
                    con =@"Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|db2006.mdf";
    
                }
                if (session == "2009")
                {
    
                    con = @"Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|fee.mdf";
                }
                if (session == "2010")
                {
                    //con = @"Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|library.mdf";
                    con = @"server=nikhil;uid=sa;password=saw;database=library";
                }
                if (session == "2009")
                {
                    //con = @"Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|library2009.mdf";
                    con = @"server=nikhil;uid=sa;password=saw;database=library";
                    //con = @"Data Source=.\SQLExpress;Database=school2010;Integrated Security=SSPI;";
                }
                return (con);
                
    
            }
        }
    }


    Wednesday, January 26, 2011 12:07 AM