Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

How to get the name of the database?



I need to get the main episerver database name to use with entity framework.

I know I could get it from System.Configuration.ConfigurationManager.ConnectionStrings but I will not have the name of the string so this is useless.

It could be retrieved from EPiServer.Data.Providers.IDatabaseFactory, but that interface is obsolete :(

Is there a built in method that will return the main episerver database name?

Edited, Jan 11, 2019 17:01

Not sure what you meant but episerver cms connection string name is always EPiServerDB

Jan 11, 2019 21:12

The connections.config file has the following strings:

<add name="EPiServerDB" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|EPiServer.Cms.mdf;Initial Catalog=EPiServer.Cms;Connection Timeout=60;Integrated Security=True;MultipleActiveResultSets=True" />

referenced in this part of the web.config:

<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="EPiServerDB" applicationName="/" />

The name of this string is EPiServerDB. But what when this is changed? Then my querry for the database name, using the connection string will result in an error.

So how can I get the correct name of the database episerver uses, without specifing any name, that could potentialy be changed by a user somewhere down the line?

Jan 14, 2019 12:13

the connectionstring name is a const and will not be changed, because it will break all other parts in the system. 

Jan 14, 2019 12:18

I am making a nuget package, that will save some things into episerver database.

I dont know what is the name of the dabase, and I dont know what is the name of the connection string.

I need to use the episerver database and cannot create a seperate database.

I would prefer to use Entity Framework.

It all boils down to " How to extract the name of the main episerver database without explicit names and magic strings."

Edited, Jan 14, 2019 13:26
var epiDataOptions = context.Locate.Advanced.GetInstance<DataAccessOptions>();
var connectionName = epiDataOptions.DefaultConnectionStringName;  // will return `EPiServer` or any other configured connection string name

name of the connection string can be changed by adding following line in web.config file (or any other where you have <episerver.dataStore> section):

    <dataSettings connectionStringName="ThisIsMyConnectionName" />

but default one is "EPiServerDB"

Jan 15, 2019 17:07

`context.Locate.Advanced` is just a shortcut used in init modules to get to Service Locator

Jan 15, 2019 17:08

Thank you!

Jan 16, 2019 12:42
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.