Click here to Skip to main content
15,434,219 members
Home / Discussions / C#
   

C#

 
QuestionXMODEM File Transfer Pin
Sifar - 023-Jun-09 18:41
MemberSifar - 023-Jun-09 18:41 
AnswerRe: XMODEM File Transfer Pin
Philip.F23-Jun-09 21:33
MemberPhilip.F23-Jun-09 21:33 
QuestionXML -- Call me stupid -- LOL [modified] Pin
JollyMansArt23-Jun-09 16:40
MemberJollyMansArt23-Jun-09 16:40 
AnswerRe: XML -- Call me stupid -- LOL Pin
N a v a n e e t h23-Jun-09 18:13
MemberN 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
MemberJollyMansArt23-Jun-09 19:04 
AnswerRe: XML -- Call me stupid -- LOL [modified] Pin
JollyMansArt23-Jun-09 19:58
MemberJollyMansArt23-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
MemberSk9323-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
MemberEslam Afifi23-Jun-09 18:25 
QuestionHttp post [modified] Pin
kibromg23-Jun-09 12:32
Memberkibromg23-Jun-09 12:32 
AnswerRe: Http post Pin
Gary Stafford23-Jun-09 14:34
MemberGary Stafford23-Jun-09 14:34 
Questionactive directory users Pin
caiena23-Jun-09 10:58
Membercaiena23-Jun-09 10:58 
AnswerRe: active directory users [modified] Pin
EliottA23-Jun-09 11:01
MemberEliottA23-Jun-09 11:01 
GeneralRe: active directory users Pin
caiena23-Jun-09 11:15
Membercaiena23-Jun-09 11:15 
AnswerRe: active directory users [modified] Pin
rolandm661023-Jun-09 11:49
Memberrolandm661023-Jun-09 11:49 
QuestionBreakpoint problem Pin
Dan Neely23-Jun-09 10:21
MemberDan Neely23-Jun-09 10:21 
AnswerRe: Breakpoint problem Pin
EliottA23-Jun-09 10:28
MemberEliottA23-Jun-09 10:28 
GeneralRe: Breakpoint problem Pin
Dan Neely23-Jun-09 10:42
MemberDan Neely23-Jun-09 10:42 
GeneralRe: Breakpoint problem Pin
EliottA23-Jun-09 10:44
MemberEliottA23-Jun-09 10:44 
GeneralRe: Breakpoint problem Pin
Dan Neely23-Jun-09 10:50
MemberDan Neely23-Jun-09 10:50 
GeneralRe: Breakpoint problem Pin
EliottA23-Jun-09 10:52
MemberEliottA23-Jun-09 10:52 
AnswerRe: Breakpoint problem Pin
Christian Graus23-Jun-09 10:28
mveChristian Graus23-Jun-09 10:28 
GeneralRe: Breakpoint problem Pin
Dan Neely23-Jun-09 10:42
MemberDan Neely23-Jun-09 10:42 
GeneralRe: Breakpoint problem Pin
Christian Graus23-Jun-09 10:52
mveChristian Graus23-Jun-09 10:52 
GeneralRe: Breakpoint problem Pin
Dan Neely23-Jun-09 11:07
MemberDan 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.