Click here to Skip to main content
16,021,112 members

Comments by tenletters (Top 2 by date)

tenletters 16-Dec-10 0:02am View    
So, I am going to assume you're using C# for this.
Create a common class so your application can reuse it.

At the top of the .cs add in:
using System.Security.Principal;

Then you'll want to grab the machine name with the following line:
WindowsIdentity.GetCurrent().Name.ToString();

This will return a string in the format computername/username. Just do a split and take the first part of the array to get the computername.

Then you'd set a XML file in the following way:
<connectionstrings>
<connectionstring id="homePCName" value="your connection string here">
<connectionstring id="officePCName" value="your other connection string here">


Just call it connections.xml or something similar.

Then you open your xml document later in the code with:
XmlDocument xmlConnectionsDocument = new XmlDocument();
xmlConnectionsDocument.Load(Server.MapPath("/xml/connections.xml"));

Hope that helps, I'm converting my code from VB.Net so it might not work perfectly.
tenletters 15-Dec-10 23:03pm View    
In that case I would do something similar to find the machine name it's deployed to. Then you could just match the machine name to a value and grab the connection string from an xml file. Or if you only have a few options that shouldn't change you could do a switch statement in your code. I recommend the xml file.

Theory is pretty much the same, just all the project components from the web application aren't available to you.