Click here to Skip to main content
15,887,821 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Update Connection String Pin
Greg Chelstowski2-Mar-09 2:13
Greg Chelstowski2-Mar-09 2:13 
GeneralRe: Update Connection String Pin
Vimalsoft(Pty) Ltd2-Mar-09 2:23
professionalVimalsoft(Pty) Ltd2-Mar-09 2:23 
AnswerRe: Update Connection String Pin
Greg Chelstowski2-Mar-09 2:12
Greg Chelstowski2-Mar-09 2:12 
GeneralRe: Update Connection String Pin
Vimalsoft(Pty) Ltd2-Mar-09 2:31
professionalVimalsoft(Pty) Ltd2-Mar-09 2:31 
GeneralRe: Update Connection String Pin
Greg Chelstowski2-Mar-09 2:41
Greg Chelstowski2-Mar-09 2:41 
GeneralRe: Update Connection String Pin
Vimalsoft(Pty) Ltd2-Mar-09 2:47
professionalVimalsoft(Pty) Ltd2-Mar-09 2:47 
GeneralRe: Update Connection String Pin
Greg Chelstowski2-Mar-09 2:53
Greg Chelstowski2-Mar-09 2:53 
GeneralRe: Update Connection String Pin
Vimalsoft(Pty) Ltd2-Mar-09 19:45
professionalVimalsoft(Pty) Ltd2-Mar-09 19:45 
hi Greg

i Done it this way


<connectionStrings>
    
<add name="string1" connectionString="datasource=VUYISWA_SERVER ;User ID=VA;password=MASEKO;Database=NEWDT" providerName="System.Data.SqlClient" />
 
</connectionStrings>


And the C# code is like this


/*This Function will change the Connection string in the web.congif file based on the Database that exists on the
 * session Variable. If there is null then set odirect3 as a current Database name.
 */
public void UpdateConfig()
{

    String StrDatabase; //This will be Comming from a Session

    if (Session["ActiveDatabase"] != null)
    {
        StrDatabase = Convert.ToString(Session["ActiveDatabase"]);
        string connString = ConfigurationManager.ConnectionStrings["string1"].ConnectionString;
        connString = connString.Replace("NEWDT", StrDatabase);
    }
    else
    {
        StrDatabase = "oDirectv3";
        string connString = ConfigurationManager.ConnectionStrings["string1"].ConnectionString;
        connString = connString.Replace("NEWDT", StrDatabase);
    }
}


And am Calling this Function like this from a page load

protected void Page_Load(object sender, EventArgs e)
  {

      Session["ActiveDatabase"] = "Mafutha";

      UpdateConfig();

      Response.Write("<script> alert('Wow i did it');</script>");


  }


Remember this is just a test to see if it will change the Database in the Connection String. After i run it i get the alert no Errors but the Connection String has not been changed to "Mafutha".

What could be the Problem ?

Vuyiswa Maseko,

Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za

GeneralRe: Update Connection String Pin
Greg Chelstowski2-Mar-09 20:50
Greg Chelstowski2-Mar-09 20:50 
GeneralRe: Update Connection String Pin
Vimalsoft(Pty) Ltd4-Mar-09 1:27
professionalVimalsoft(Pty) Ltd4-Mar-09 1:27 
QuestionCan i use my own User Registartion Information Class with ASP .NET Login controls Pin
The One2-Mar-09 1:49
The One2-Mar-09 1:49 
AnswerRe: Can i use my own User Registartion Information Class with ASP .NET Login controls Pin
Abhishek Sur2-Mar-09 3:55
professionalAbhishek Sur2-Mar-09 3:55 
QuestionError occuring while developin with ASP.NET Pin
VeeKeyBee2-Mar-09 1:46
VeeKeyBee2-Mar-09 1:46 
AnswerRe: Error occuring while developin with ASP.NET Pin
Vimalsoft(Pty) Ltd2-Mar-09 1:54
professionalVimalsoft(Pty) Ltd2-Mar-09 1:54 
QuestionImport data from Excel sheet to sql Database-asp.net 2.0 Pin
Member 46590012-Mar-09 1:26
Member 46590012-Mar-09 1:26 
AnswerRe: Import data from Excel sheet to sql Database-asp.net 2.0 Pin
Greg Chelstowski2-Mar-09 1:34
Greg Chelstowski2-Mar-09 1:34 
GeneralRe: Import data from Excel sheet to sql Database-asp.net 2.0 Pin
Member 46590012-Mar-09 18:09
Member 46590012-Mar-09 18:09 
QuestionMethod? Pin
Karthick_gc2-Mar-09 1:05
Karthick_gc2-Mar-09 1:05 
AnswerRe: Method? Pin
Gaurav K Singh2-Mar-09 1:13
Gaurav K Singh2-Mar-09 1:13 
GeneralRe: Method? Pin
Karthick_gc2-Mar-09 1:23
Karthick_gc2-Mar-09 1:23 
GeneralRe: Method? Pin
mr_muskurahat2-Mar-09 1:26
mr_muskurahat2-Mar-09 1:26 
QuestionHow to export data from datagrid to .mdb format Pin
ballameharmurali2-Mar-09 0:21
ballameharmurali2-Mar-09 0:21 
AnswerRe: How to export data from datagrid to .mdb format Pin
Greg Chelstowski2-Mar-09 0:48
Greg Chelstowski2-Mar-09 0:48 
Questionthe state information is invalid for this page and might be corrupted. Pin
NidhiKanu1-Mar-09 23:31
professionalNidhiKanu1-Mar-09 23:31 
AnswerRe: the state information is invalid for this page and might be corrupted. Pin
Vimalsoft(Pty) Ltd1-Mar-09 23:38
professionalVimalsoft(Pty) Ltd1-Mar-09 23:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.