473,802 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using stream reader to read and store it in a variable in C#

21 New Member
Hi Everyone,
I am having a txt file config.txt on application start up path.I need to read that file line by line using a delimiter ; or , and store the values in a variable to connect to the database. Currently I am hardcoding the initial database connection.

Expand|Select|Wrap|Line Numbers
  1. //code
  2. // Mysql database initialize and connection to Profile    
  3.             string strprofile = "DRIVER={MySQL ODBC 5.1 Driver};" + "SERVER=192.168.1.9;" + "DATABASE=profile;" + "UID=root;" + "PASSWORD=selva123;" + "OPTION=3";
  4. //code
I have to read the following from txt file and store in varable so that I can pass this to the connection string.If anyone have any other way of doing this will be great.Thanks in advance.

Server:
Database:
UID:
Password:
Dec 29 '08 #1
7 3409
Plater
7,872 Recognized Expert Expert
Use a StreamReader, then ReadLine() then split on ":" ?
Dec 29 '08 #2
andyehi
21 New Member
HI A simple example will help me more.I am really new to this stuff.
Dec 29 '08 #3
mldisibio
190 Recognized Expert New Member
If you are writing the application in .NET, then you can add a config file to your project (Project -> Add New Item -> Config file).

Within this file you can add a connectionStrin gs element with all this information in text/xml format. It will be copied to your output directory and you can change it as needed without recompiling your application. .Net knows how to read this file and create your database connection from it.

See: ConnectionStrin gSettings Class for examples and explanation.
Dec 29 '08 #4
andyehi
21 New Member
I am developing a windows application and I dont have that option.Please give me an example to read and store in variable with the delimiter ; .Thanks
Dec 29 '08 #5
mldisibio
190 Recognized Expert New Member
Yes you do. The new item is called "Applicatio n Configuration File." This is the preferred way to store connection string data and passwords. Sometimes the terminology is different for web application or windows applications, but the concept and practice is exactly the same for both.

Please slow down and read the above MSDN section and some of the links it contains. If you are "really new to this stuff" as you say, then now is a good time to learn the correct way to store and retrieve connection string items.
Dec 29 '08 #6
mldisibio
190 Recognized Expert New Member
Here is a better link for starting with connection strings:

Working with Connection Strings.
Dec 29 '08 #7
andyehi
21 New Member
Thanks everyone will do what you suggested
Dec 29 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2530
by: Todd Bright | last post by:
Is there a way to get the current XmlNode from the reader while in the validation event handler? What I'd like to do is display the error message along with the name of its parent node. In my XML format, there are parent nodes named differently with some of the same names for child nodes, so when I get an error message that references the 'LOGICALPOCKET' node that could be under more than one different parent node. I need to be able to...
5
17702
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the file as displayed when I open the xml file in VS .net 2003 IDE. When I perform the same procedure in C# the stream reader obkect displays a chaotic mess. Lots of whitespace after and "\r" and "\n" after each element. The problem is that I cannot...
2
23612
by: Bob Rock | last post by:
I already found an alternative way to accomplish this (using ReadBytes), still I'd like to understand why I'm getting and error reading a text file using the following method. The exception is returned on the ReadString call. public string BinaryRead(string fileName) { FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
0
3945
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
3
3693
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use by another process. This occurs even if I release the object using fs.Close() and fs = Nothing. Please help (my code is given below) Best regards
1
1918
by: Daniel | last post by:
Does system.xml have any way to transofrm data with an xswl style sheet using strings like MSXML2 does? how to convert this to use System.XML so i do not depend on MSXML2 interop? static public string XslTransform(string style, string strdata) { MSXML2.IXMLDOMDocument pDoc = new MSXML2.DOMDocumentClass(); pDoc.async = false; pDoc.loadXML(strdata);
0
3140
by: VeeraLakshmi | last post by:
I am doing a project for internet control using Java,PHP and MySql.All sites should go through the proxy server only.We are giving access rights as allow or deny to the sites.If we type the url,first it will ask for authentication.After giving username and password,the authentication will be confirmed and if the site has access right as allow,the website will open else a page will be displayed.There we can send request mail to the...
0
2153
by: nagashree | last post by:
Hi, i want to compress the file or directory i am able to do that can anybody help me to decompress the file when i double click on the zipped file i am getting the error message as compressed(zipped) folder is invalid or corrupted. I am using VB.NET .Please help me out in this regard...Thank you in advance. Here is the code for that. Public Class clsZip
0
2923
by: dipalipatel | last post by:
Hi, I have a very hard time to insert Image into Sqlce Database. Table : Test Column : mypic Datatype : image below the code while i am inserting
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10538
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10305
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.