16,021,112 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Visual Basic questions
View Javascript questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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.