Click here to Skip to main content
16,007,163 members
Home / Discussions / Database
   

Database

 
Questionconfigure filestream for sqlserver2008 Pin
Pankaj Saha29-Sep-08 21:47
Pankaj Saha29-Sep-08 21:47 
AnswerRe: configure filestream for sqlserver2008 Pin
Wendelius30-Sep-08 5:34
mentorWendelius30-Sep-08 5:34 
QuestionCrystal Reports 2005- Group totals in the page footer Pin
Colwin29-Sep-08 20:22
Colwin29-Sep-08 20:22 
AnswerRe: Crystal Reports 2005- Group totals in the page footer Pin
ChandraRam29-Sep-08 23:10
ChandraRam29-Sep-08 23:10 
GeneralRe: Crystal Reports 2005- Group totals in the page footer Pin
Colwin30-Sep-08 20:35
Colwin30-Sep-08 20:35 
GeneralRe: Crystal Reports 2005- Group totals in the page footer Pin
Colwin6-Oct-08 20:25
Colwin6-Oct-08 20:25 
GeneralRe: Crystal Reports 2005- Group totals in the page footer Pin
ChandraRam7-Oct-08 5:16
ChandraRam7-Oct-08 5:16 
QuestionFunction to create Enterprise Library Database object from Connection String Pin
nwaheed29-Sep-08 19:57
nwaheed29-Sep-08 19:57 
Some time back I had a requirement of using connecting string passed as command line argument to an application.

The problem was that the application was using Enterprise Library 1.1 which uses dataconfig.config file for database connection information.

After some research i was able to find a way to create Enterprise Library Database object from Connection String. I thought that this would also be useful to other developers.

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration; 

        private static Database CreateDatabaseFromConnectionString(string connString)
        {
            System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder(connString);


            DatabaseSettings settings = new DatabaseSettings();
            DatabaseTypeData type = new DatabaseTypeData("Sql Server", "Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
            settings.DatabaseTypes.Add(type);


            ConnectionStringData connectionString = new ConnectionStringData("DBConnection");


            connectionString.Parameters.Add(new ParameterData("server", builder.DataSource));
            connectionString.Parameters.Add(new ParameterData("database", builder.InitialCatalog));
            connectionString.Parameters.Add(new ParameterData("integrated security", "false"));
            connectionString.Parameters.Add(new ParameterData("user id", builder.UserID));
            connectionString.Parameters.Add(new ParameterData("password", builder.Password));

            settings.ConnectionStrings.Add(connectionString);

            Microsoft.Practices.EnterpriseLibrary.Data.Configuration.InstanceData instance = new Microsoft.Practices.EnterpriseLibrary.Data.Configuration.InstanceData("DBConnection", "Sql Server", "DBConnection");
            settings.Instances.Add(instance);

            Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationDictionary configurations = new Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationDictionary();
            configurations.Add("dataConfiguration", settings);

            Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationContext context = Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManager.CreateContext(configurations);
            Database database = new DatabaseProviderFactory(context).CreateDatabase("DBConnection");
            return database;

        }


Of course you can also set the integrated security parameter if you want.

cheers
Questionhoe to return more than parameter Pin
prasadbuddhika29-Sep-08 19:39
prasadbuddhika29-Sep-08 19:39 
AnswerRe: hoe to return more than parameter Pin
HemJoshi29-Sep-08 20:18
HemJoshi29-Sep-08 20:18 
Questionconvert font Pin
tungcan5diop29-Sep-08 18:16
tungcan5diop29-Sep-08 18:16 
AnswerRe: convert font Pin
HemJoshi29-Sep-08 19:10
HemJoshi29-Sep-08 19:10 
Questionxds Pin
postonoh29-Sep-08 11:34
postonoh29-Sep-08 11:34 
AnswerDuplicate post Pin
Mycroft Holmes29-Sep-08 14:54
professionalMycroft Holmes29-Sep-08 14:54 
QuestionNumber of opened accounts per month Pin
matt23lucier29-Sep-08 9:40
matt23lucier29-Sep-08 9:40 
AnswerRe: Number of opened accounts per month Pin
leckey29-Sep-08 10:53
leckey29-Sep-08 10:53 
AnswerRe: Number of opened accounts per month Pin
Blue_Boy29-Sep-08 11:21
Blue_Boy29-Sep-08 11:21 
QuestionRe: Number of opened accounts per month Pin
nelsonpaixao29-Sep-08 12:26
nelsonpaixao29-Sep-08 12:26 
QuestionSQL Help Required Pin
munklefish29-Sep-08 5:07
munklefish29-Sep-08 5:07 
AnswerRe: SQL Help Required Pin
Kschuler29-Sep-08 6:15
Kschuler29-Sep-08 6:15 
Question# of records between 2 times Pin
wienfall200329-Sep-08 5:06
wienfall200329-Sep-08 5:06 
AnswerRe: # of records between 2 times Pin
Wendelius29-Sep-08 5:11
mentorWendelius29-Sep-08 5:11 
GeneralRe: # of records between 2 times Pin
wienfall200329-Sep-08 5:23
wienfall200329-Sep-08 5:23 
GeneralRe: # of records between 2 times Pin
Wendelius29-Sep-08 5:42
mentorWendelius29-Sep-08 5:42 
GeneralRe: # of records between 2 times Pin
wienfall200329-Sep-08 7:25
wienfall200329-Sep-08 7:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.