Hello to everyone...

Hi I'm new to C# programming, but i have a background in programming specially
in c, c++ and vb 6, now i'm trying to study the c# programming, i have a problem to solve
i am doing a project in c# that the sql connection string of the database of my program is in the ini file. how can i call the the content of the ini file in the program.

Can somebody help me...

Thanks

foxfire

actually in C# preferred method for saving connectionstring is using app.config file.

<configuration>
....
<connectionStrings>
		<add name="your_connection_string_name" connectionString="your_connection_string" />
	</connectionStrings>
....
</configuration>

you can access it in your code with this:

string connString = ConfigurationManager.ConnectionStrings["your_connection_string_name"].ConnectionString;

don't forget to add:

using System.Configuration;

True, using INI files in dotNet applications is considered a security risk by Microsoft, and I no longer use them myself, but there is a need for them in Legacy replacements. I posted an ini class up on DaniWeb a long time ago. You should still be able to find it, if not, give me a message, and I will repost it.

On the subject of the built in Configuration of dotNet, there are some gotchas to be aware of.
1) If you use versioning software, the configuration is reset to its defaults each time the file is versioned. IOW your user loses any settings they set in the configuration.

2) User configuration items are also lost each time you move the file to another directory.

3) Deleting the application does not remove the associated configuration file from the hard drive.

4) If you add a new setting (post delivery), you must perform update methods during installation to merge the new settings into the existing configuration. If you don't then the application will read the old configuration that is missing the new setting, and you get Exceptions. If this happens, find the config file in the local settings, and delete it, or manually edit it, or deploy an application that can fix it.

5) Vista uses a different file extension for the configuration file than XP.

// Jerry

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.