Connection Strings in Code?

Posted by Community Admin on 03-Aug-2018 17:46

Connection Strings in Code?

All Replies

Posted by Community Admin on 10-Mar-2011 00:00

Hello,

I added a connection string to Sitefinity by going to Administration --> Settings --> Advanced --> Data --> Connection Strings.

I am creating some custom user controls that I need to interact with a database other than the one Sitefinity uses to store all its data.

How can I access the connection string I created above in code?

Thanks.

Posted by Community Admin on 10-Mar-2011 00:00

Hello Network,

Bellow is some quick sample code which you can use to access connection strings defined in the data configurations:

ConfigManager configManager = Config.GetManager();
configManager.Provider.SuppressSecurityChecks = true;
DataConfig dataConfig = configManager.GetSection<DataConfig>();
//get the sitefinity element in the collection
ConnStringSettings Sitefinity = dataConfig.ConnectionStrings["Sitefinity"];
//get the connection string
string connectionString = Sitefinity.ConnectionString;
PagesConfig pagesConfig = configManager.GetSection<PagesConfig>();

Greetings,
Radoslav Georgiev
the Telerik team

This thread is closed