p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 3.5 Professionals (http://p2p.wrox.com/forumdisplay.php?f=352)
-   -   Define LocalSqlServer dynamically at run time (http://p2p.wrox.com/showthread.php?t=91872)

hdossantos January 10th, 2014 08:53 AM

Define LocalSqlServer dynamically at run time

As it's the first time I ask a question here I hope I'm doing it at the right place...

Here is my question : is there a way to define the LocalSqlServer string dynamically at run time?
I'm using .net 3.5, VS2008, c# and VB and it's for web projects.

Why do I want to do this?
Because I want the LocalSqlServer connection string data (host, login, password) to be centralised and not hard code on the web.config.

Ex: these data will be stored in the server system variables, managed by the IT, the websites will have to load and get these data to create the connectring at startup, there are many websites most of them will be using the same DB for LocalSqlServer.

Has I'm using the membership tables I must specify the LocalSqlServer string.

I hope my question and what I'm trying to do is enought clear... I'm yet far from being fluent in english [8)] !



rstelma January 10th, 2014 04:06 PM

So you want your users to type in the connection string in when they log in?

hdossantos January 10th, 2014 05:27 PM


No, just to be able to define the connection string for LocalSqlServer at the start of my application.
In this way I can create the connection based on aliases and server variables.
no real server name/ip, userid or password will be used in the code (I use SQL Users for connection)

But with some luck I found, a couple of hours ago, was I looking for!

In the web.config I specify custom Providers for the functionalities (Membership, Roles, WebParts, ...) I use that are using LocalSqlServer connection by default, instead I make then point to a Dummy SQL Connection string and I make my custom Provider be based on a SQL provider class (SqlMembershipProvider, SqlRoleProvider, ...) that is defined in my project.
On these SQL Provider classes I override the Initialize method allowing me to bypass the Dummy connection string and create the connection string as I want based on whatever variables I need.

So for me the topic could be claused!

Any way thanks for your help.
Best Regards


All times are GMT -4. The time now is 08:52 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.