473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

21
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 3389
Plater
7,872 Expert 4TB
Use a StreamReader, then ReadLine() then split on ":" ?
Dec 29 '08 #2
andyehi
21
HI A simple example will help me more.I am really new to this stuff.
Dec 29 '08 #3
mldisibio
190 Expert 100+
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 connectionStrings 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: ConnectionStringSettings Class for examples and explanation.
Dec 29 '08 #4
andyehi
21
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 Expert 100+
Yes you do. The new item is called "Application 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 Expert 100+
Here is a better link for starting with connection strings:

Working with Connection Strings.
Dec 29 '08 #7
andyehi
21
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
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...
5
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...
2
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...
0
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....
3
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...
1
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...
0
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...
0
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...
0
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...

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.