-5

I want to write and read my connection string in the Baglanti.cs class, but I don't know anything about this. I trying this first time. I search on Google, but I can't find any clear information.

KoRnTuNeS
  • 73
  • 3
  • 11
  • A .cs file is code file that is converted to runtime code during compilation. After successful one you end up with an application, library and so on. When your code is executed you have no such files in execution context, they are part of the whole compiled app/lib. – Rolice Apr 07 '16 at 07:17
  • refer http://stackoverflow.com/questions/6134359/read-connection-string-from-web-config – kudlatiger Apr 07 '16 at 07:17
  • why do you have .ini in the end of caption?? – kudlatiger Apr 07 '16 at 07:21
  • my boss want me do with .ini file :D – KoRnTuNeS Apr 07 '16 at 07:26

1 Answers1

2

The .NET way of doing this is using app.config file instead of .ini file

  1. Create a new Application Configuration File with the following content

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <connectionStrings>
            <add name="MyConnectionString" connectionString="YourConnectionString" providerName="System.Data.SqlClient" />
        </connectionStrings>
    </configuration>
    
  2. Retrieve the connectionString inside your application using

    var connection = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
    

Check out MSDN: Connection Strings and Configuration Files

dknaack
  • 60,192
  • 27
  • 155
  • 202