Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing connection string to dll?

I am trying to make some simple libraries that require database access. What I don't get is how to pass the connection string to the library... Right now I have a db.config in my dll, but I'm not sure how to reference it from within the dll etc...

This is how I have setup the libraries

[Solution File]

  • Library1
    • db.config
  • Library2
    • linked db.config

<configuration>
        <!-- Connection string -->
    </configuration>
  1. How do I reference the db.config from within dll?
  2. How do I reference the db.config from a web applications web.config?
like image 581
chobo Avatar asked Mar 17 '26 00:03

chobo


1 Answers

Real simple:

1) If this happens to be a .Net .dll, you can store it in "app.config" or "web.config":

Example:

<?xml version="1.0" encoding="utf-8" ?>
  <configuration>
    <connectionStrings>
      <add name="DigiBrd"
           connectionString="server=localhost;user id=****;Password=****;database=DigiBrd"
           providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
</configuration>

String cnString =
  ConfigurationManager.ConnectionStrings["DigiBrd"].ConnectionString;

2) You can also store the connection string anywhere that the .dll can read it. For example, you can use an .ini file or the registry.

3) You can implement a getConnectionString() method in your .dll.

4) Etc. etc. etc.

like image 174
paulsm4 Avatar answered Mar 18 '26 15:03

paulsm4



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!