Click here to Skip to main content
15,892,674 members
Home / Discussions / C#
   

C#

 
QuestionHow to get active window event Pin
Jacobb Michael23-Jun-09 19:37
Jacobb Michael23-Jun-09 19:37 
AnswerRe: How to get active window event Pin
Anubhava Dimri23-Jun-09 19:50
Anubhava Dimri23-Jun-09 19:50 
GeneralRe: How to get active window event Pin
Jacobb Michael24-Jun-09 1:18
Jacobb Michael24-Jun-09 1:18 
AnswerRe: How to get active window event Pin
Anubhava Dimri24-Jun-09 2:11
Anubhava Dimri24-Jun-09 2:11 
GeneralRe: How to get active window event Pin
Jacobb Michael24-Jun-09 2:18
Jacobb Michael24-Jun-09 2:18 
GeneralRe: How to get active window event Pin
Anubhava Dimri24-Jun-09 2:32
Anubhava Dimri24-Jun-09 2:32 
QuestionIs there any learning docs for begines? Pin
behesht23-Jun-09 19:01
behesht23-Jun-09 19:01 
AnswerRe: Is there any learning docs for begines? Pin
behesht23-Jun-09 19:22
behesht23-Jun-09 19:22 
GeneralRe: Is there any learning docs for begines? Pin
Anubhava Dimri23-Jun-09 19:42
Anubhava Dimri23-Jun-09 19:42 
AnswerRe: Is there any learning docs for begines? Pin
JollyMansArt23-Jun-09 19:29
JollyMansArt23-Jun-09 19:29 
QuestionXMODEM File Transfer Pin
Sifar - 023-Jun-09 18:41
Sifar - 023-Jun-09 18:41 
AnswerRe: XMODEM File Transfer Pin
Philip.F23-Jun-09 21:33
Philip.F23-Jun-09 21:33 
QuestionXML -- Call me stupid -- LOL [modified] Pin
JollyMansArt23-Jun-09 16:40
JollyMansArt23-Jun-09 16:40 
AnswerRe: XML -- Call me stupid -- LOL Pin
N a v a n e e t h23-Jun-09 18:13
N a v a n e e t h23-Jun-09 18:13 
QuestionRe: XML -- Call me stupid -- LOL [modified] Pin
JollyMansArt23-Jun-09 19:04
JollyMansArt23-Jun-09 19:04 
AnswerRe: XML -- Call me stupid -- LOL [modified] Pin
JollyMansArt23-Jun-09 19:58
JollyMansArt23-Jun-09 19:58 
AnswerRe: XML -- Call me stupid -- LOL Pin
OriginalGriff23-Jun-09 21:27
mveOriginalGriff23-Jun-09 21:27 
GeneralRe: XML -- Call me stupid -- LOL Pin
Sk9323-Jun-09 23:07
Sk9323-Jun-09 23:07 
As Navaneeth says above, you probably want to use an app.config file for storing your connection string.

There are two ways of storing the connection string in said file.
The first is quick, dirty and I don't like it, but I'll show you anyway... Dead | X|

The connection string can be stored within the "appSettings" section of your app.config file, as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<appSettings>
		<add key="MainDB" value="Data Source=127.0.0.1;Initial Catalog=MainDB;User ID=usr;Password=pwd"/>		
	</appSettings>	
</configuration>


To then read this setting from within your c# app, you'd need to use the following code:
System.Configuration.AppSettingsReader reader = new System.Configuration.AppSettingsReader();
string connString = (string)reader.GetValue("MainDB", typeof(string));



The reason I don't like the above method, is because the app.config specification includes a section specifically for connection strings.

Below is an example of an app.config that uses this section:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<connectionStrings>
		<add name="MainDB" providerName="System.Data.SqlClient" connectionString="Data Source=127.0.0.1;Initial Catalog=MainDB;User ID=usr;Password=pwd"/>		
	</connectionStrings>
</configuration>


To then read this section, you first need to add a reference to "System.Configuration" to your project.
Then, you can use the code below:
string s = System.Configuration.ConfigurationManager.ConnectionStrings["MainDB"].ConnectionString;


Much nicer Cool | :cool:
AnswerRe: XML -- Call me stupid -- LOL Pin
Eslam Afifi23-Jun-09 18:25
Eslam Afifi23-Jun-09 18:25 
QuestionHttp post [modified] Pin
kibromg23-Jun-09 12:32
kibromg23-Jun-09 12:32 
AnswerRe: Http post Pin
Gary Stafford23-Jun-09 14:34
Gary Stafford23-Jun-09 14:34 
Questionactive directory users Pin
caiena23-Jun-09 10:58
caiena23-Jun-09 10:58 
AnswerRe: active directory users [modified] Pin
EliottA23-Jun-09 11:01
EliottA23-Jun-09 11:01 
GeneralRe: active directory users Pin
caiena23-Jun-09 11:15
caiena23-Jun-09 11:15 
AnswerRe: active directory users [modified] Pin
rolandm661023-Jun-09 11:49
rolandm661023-Jun-09 11:49 

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.