locked
EntLib -> Data -> Connectionstring RRS feed

  • Question

  • User2056339653 posted
    Vent: I am curious to know what genius decided to release this great big Enterprise Library with no functionality to change connection strings without manually editing the config file. Oh yeah everybody uses trusted security and the developer always knows which server and database the user will be hitting. And I am sure all your users out there are willing to provide you with their username and password so that YOU can one-off config files for them. Damn these blocks. Mike "Pissed Off" Anderson
    Friday, March 4, 2005 12:18 PM

All replies

  • User1014708013 posted
    Hmmmmm, did you take a look at the "Enterprise Library Configuration" item in your start menu, and did you even bother opening up the help files that came with the Enterprise Library?? Cheers, Imar
    Sunday, March 6, 2005 3:15 PM
  • User2056339653 posted
    Hmmmmmmm... I think so. Did you open the configuration stuff? Did you read the help files? Did you see newbie after my name? If I seem a little snide, well... Maybe you have figured out how to set user name and password at RUNTIME without extending the block. If so I am sure there are lots of us out there that would like to know. Cheers to you Imar, Mike
    Monday, March 7, 2005 7:41 AM
  • User1014708013 posted
    No, I didn't see newbie behind your name. Anyway, open up the help, choose Data Access Application Block | Developing using the Data Access Application Block and finally choose Entering Configuration Information That section guides you through the configuration process, incluing instruction on setting up the password parameters.... Cheers, Imar
    Monday, March 7, 2005 3:09 PM
  • User2056339653 posted
    Been there, done that. I am trying to set username, password at runtime. The data access config file is configured as readonly where the config blocks are concerned and the user name and password are not exposed by the data blocks. Of course I can extend the data blocks and will do so later this week. Regards, Mike
    Tuesday, March 8, 2005 8:20 AM
  • User1577934194 posted
    I'm interested in how to have multiple database instances in an Application, and switch back and forth between them.  One for development, and one for production.  I've located in the config file where it determines the default Database Instance but cant find anywhere in the tool that allows you to change it.  The spot is in the [defaultInstance="Database Instance 1"] attribute for the enterpriseLibrary.databaseSettings node.  I want to be able to use the tool to switch between them but it doesnt appear to let me.

    Here's the Configuration file itself:

    <dataConfiguration>
      <xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="Database Instance 1" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
          <databaseTypes>
            <databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
          </databaseTypes>
          <instances>
            <instance name="Database Instance 2" type="Sql Server" connectionString="Server3Test" />
            <instance name="Database Instance 1" type="Sql Server" connectionString="LocalMyNorthwind" />
          </instances>
          <connectionStrings>
            <connectionString name="Server3Test">
              <parameters>
                <parameter name="database" value="Test1" isSensitive="false" />
                <parameter name="Integrated Security" value="True" isSensitive="false" />
                <parameter name="server" value="Server3" isSensitive="false" />
              </parameters>
            </connectionString>
            <connectionString name="LocalMyNorthwind">
              <parameters>
                <parameter name="database" value="MyNorthwind" isSensitive="false" />
                <parameter name="Integrated Security" value="True" isSensitive="false" />
                <parameter name="server" value="localhost" isSensitive="false" />
              </parameters>
            </connectionString>
          </connectionStrings>
        </enterpriseLibrary.databaseSettings>
      </xmlSerializerSection>
    </dataConfiguration>

    Tuesday, April 5, 2005 3:00 PM
  • User2056339653 posted

    You use a string in your call to create database to identify the connection definition you wish to use.

    // use default
    Database db = DatabaseFactory.CreateDatabase();

    // use named
    Database db = DatabaseFactory.CreateDatabase("Server3Test");

    You could put an item in you app.config or web.config file that tells your code at runtime which to use.

    Database db = DatabaseFactory.CreateDatabase( (string)ConfigurationSettings.AppSettings["DB2Use"]);

    hth,

    Mike

    Wednesday, April 13, 2005 8:06 AM
  • User346404730 posted
    I am also looking for a way to change the database at runtime and still use EntLib.

    As an alternative to dealing with multiple instances, at runtime I set Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings.DefaultInstance.

    Dim dataConfigurationContext As ConfigurationContext = ConfigurationManager.GetCurrentContext()
    Dim databaseInstances As New Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings
    databaseInstances = DirectCast(dataConfigurationContext.GetConfiguration( _
                databaseInstances.SectionName), _
                Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings)
    'This is a string from a combobox the user selected populated from DatabaseSettings.Instances collection.
    databaseInstances.DefaultInstance = "Database Instance2"

    However I ran into another issue with this, I am using EntLib security values and these guys are stuck with a hardcoded database value in securityConfiguration.config:

          <rolesProviders>
            <rolesProvider xsi:type="DbRolesProviderData" name="Roles Provider" database="Database Instance" />
          </rolesProviders>
          <authenticationProviders>
            <authenticationProvider xsi:type="DbAuthenticationProviderData" name="Authentication Provider" database="Database Instance" hashProvider="SHA1Managed" />
          </authenticationProviders>
          <profileProviders>
            <profileProvider xsi:type="DbProfileProviderData" name="Profile Provider" database="Database Instance" />
          </profileProviders>

    I am only using "authenticationProviders" so unless there is a more eloquent way, I was just going to copy-paste the authenticationProvider element and then make the name and database attributes equal to a specific database instance. So if I have 6 instances in dataConfiguration, then I'd have 6 authenticationProviders. I would then use this code (untested):

    Dim currentConfig As ConfigurationContext = ConfigurationManager.GetCurrentContext()
    Dim currentSecuritySettings As SecuritySettings = DirectCast(currentConfig.GetConfiguration(SecuritySettings.SectionName), SecuritySettings)          

    Dim currentAuthenticationProviderData As DbAuthenticationProviderData = DirectCast(currentSecuritySettings.AuthenticationProviders(databaseInstances.DefaultInstance), DbAuthenticationProviderData)
    Dim factoryHashProvider As New HashProviderFactory(currentConfig)
    Me._hashProvider = factoryHashProvider.CreateHashProvider(currentAuthenticationProviderData.HashProvider)


    Friday, April 15, 2005 1:18 AM
  • User1891653316 posted

    You use a string in your call to create database to identify the connection definition you wish to use.

    // use default
    Database db = DatabaseFactory.CreateDatabase();

    // use named
    Database db = DatabaseFactory.CreateDatabase("Server3Test");

    You could put an item in you app.config or web.config file that tells your code at runtime which to use.

    Database db = DatabaseFactory.CreateDatabase( (string)ConfigurationSettings.AppSettings["DB2Use"]);

    hth,

    Mike



    Hi Mike

    Can you post an example of the config file for using the named instance please?

    Thanks
    Sunday, August 14, 2005 11:33 PM
  • User2056339653 posted

    <?xml version="1.0" encoding="utf-8"?><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>

    <dataConfiguration><o:p></o:p>

      <xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"><o:p></o:p>

        <enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="WireFrame" xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data"><o:p></o:p>

          <databaseTypes><o:p></o:p>

            <databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /><o:p></o:p>

          </databaseTypes><o:p></o:p>

          <instances><o:p></o:p>

            <instance name="WireFrame" type="Sql Server" connectionString="GP_Database_Trusted" /><o:p></o:p>

          </instances><o:p></o:p>

          <connectionStrings><o:p></o:p>

            <connectionString name="GP_Database_Std"><o:p></o:p>

              <parameters><o:p></o:p>

                <parameter name="database" value="database" isSensitive="false" /><o:p></o:p>

                <parameter name="Password" value="" isSensitive="true" /><o:p></o:p>

                <parameter name="server" value="server" isSensitive="false" /><o:p></o:p>

                <parameter name="uid" value="someuser" isSensitive="false" /><o:p></o:p>

              </parameters><o:p></o:p>

            </connectionString><o:p></o:p>

            <connectionString name="GP_Database_Trusted"><o:p></o:p>

              <parameters><o:p></o:p>

                <parameter name="database" value="Northwind" isSensitive="false" /><o:p></o:p>

                <parameter name="Integrated Security" value="True" isSensitive="false" /><o:p></o:p>

                <parameter name="server" value="KCRB05D" isSensitive="false" /><o:p></o:p>

              </parameters><o:p></o:p>

            </connectionString><o:p></o:p>

          </connectionStrings><o:p></o:p>

        </enterpriseLibrary.databaseSettings><o:p></o:p>

      </xmlSerializerSection><o:p></o:p>

    </dataConfiguration><o:p></o:p>

    <o:p></o:p> 

     Let me know if you need anything else.<o:p></o:p>

     

    Monday, August 15, 2005 12:54 PM
  • User953166732 posted

    hello,
    I always need to set one of two "connectionString". how can I do?

    if (Session["modulo_monitor"] = "2")
    {
    db = DatabaseFactory.CreateDatabase("strConnection_Call");
    }
    else
    {
    db = DatabaseFactory.CreateDatabase("strConnection");
    }

    Need to somehow know what the value being selected in the web page.

    Tuesday, July 3, 2012 3:05 PM