Question regarding IDatabaseHandler & IDatabaseExecutor

Vote:
 

I'm following a tutorial related to storing custom data in Episerver, and one of the libraries referenced is IDatabaseHandler, which is obsolete. The documentation states to use IDatabaseHandler, but the property I'm looking to access from IDatabaseHandler is the ConnectionsStrings, which is not valid on that interface. Can someone provide me the best route to obtain the ConnectionStrings.ConnectionString lookup interface for the latest library, so I can access the database for creating a custom table?

Thank you,

#205570
Jul 16, 2019 23:06
Vote:
 

I ended up just getting the string directly from ConfigManager.

#205635
Jul 17, 2019 18:26
Vote:
 

Yeah, using ConfigurationManager.ConnectionStrings is indeed the easiest way to get connection strings.

But if you want an injected abstraction, you can have a look at the IDatabaseConnectionResolver interface. And if you run a Commerce solution, the IConnectionStringHandler interface is even simpler to use.

#205641
Jul 18, 2019 7:35
Vote:
 

Late to the party, but just to add - don't rely on fact that connection will always be named "EPiServerDB". it can be anything.

To get the name of the connection string used in solution - you can use "EPiServerDataStoreSection.Instance.DataSettings.ConnectionStringName" property value.

#205720
Jul 21, 2019 19:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.