c# - How to connection string in web.config from databases names in dropdown -


i have dropdown has list of databases. user has select database has use , gridview shown.

so display gridview i'm giving below connection string in code behind file.

using (sqlconnection con = new sqlconnection(@"data source=hki-d-sql05\sql2k12;initial catalog=" + dropdownlist1.selectedvalue + ";user id=sa;password=sa123")) 

but there anyways list connection string in web.congfig file? database name has selected in code behind. means server name, user id , password can given in web config initial catalog in code behind.

you can use placeholder database name in web.config (e.g. "data source=hki-d-sql05\sql2k12;initial catalog={{placeholder}};user id=sa;password=sa123"). in code behind connection string value web.config , replace placeholder selected database (using .replace("{{placeholder}}", dropdownlist1.selectedvalue)).


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -