Click here to Skip to main content
15,884,629 members
Home / Discussions / C#
   

C#

 
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 
QuestionBreakpoint problem Pin
Dan Neely23-Jun-09 10:21
Dan Neely23-Jun-09 10:21 
AnswerRe: Breakpoint problem Pin
EliottA23-Jun-09 10:28
EliottA23-Jun-09 10:28 
GeneralRe: Breakpoint problem Pin
Dan Neely23-Jun-09 10:42
Dan Neely23-Jun-09 10:42 
GeneralRe: Breakpoint problem Pin
EliottA23-Jun-09 10:44
EliottA23-Jun-09 10:44 
GeneralRe: Breakpoint problem Pin
Dan Neely23-Jun-09 10:50
Dan Neely23-Jun-09 10:50 
GeneralRe: Breakpoint problem Pin
EliottA23-Jun-09 10:52
EliottA23-Jun-09 10:52 
AnswerRe: Breakpoint problem Pin
Christian Graus23-Jun-09 10:28
protectorChristian Graus23-Jun-09 10:28 
GeneralRe: Breakpoint problem Pin
Dan Neely23-Jun-09 10:42
Dan Neely23-Jun-09 10:42 
GeneralRe: Breakpoint problem Pin
Christian Graus23-Jun-09 10:52
protectorChristian Graus23-Jun-09 10:52 
GeneralRe: Breakpoint problem Pin
Dan Neely23-Jun-09 11:07
Dan Neely23-Jun-09 11:07 

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.