Advertisement

02.15.2008 at 06:40PM PST, ID: 23167881
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

how to use DatabaseFactory.CreateDatabase()
Tags: Microsoft, Enterprise Library Database
please see attached app.config file, when i do this:
Database db = DatabaseFactory.CreateDatabase("Logging");

where Logging is an entry in my config file:

<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </configSections>
  <connectionStrings>
    <add name="Logging" connectionString="Data Source=arc-tms-db2005;Initial Catalog=Logging;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
      <dataConfiguration defaultDatabase="Logging"/>
</configuration>

i get this error:
Object reference not set to an instance of an object.

can someone help me?  thanks.
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: mmingfeilam
Solution Provided By: PockyMaster
Participating Experts: 1
Solution Grade: B
Views: 349
Translate:
Loading Advertisement...
02.16.2008 at 05:26AM PST, ID: 20909490

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.18.2008 at 12:08PM PST, ID: 20923006

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.19.2008 at 05:44PM PST, ID: 20934341

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.24.2008 at 09:24AM PST, ID: 20970565

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.24.2008 at 10:33AM PST, ID: 20970757

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.24.2008 at 11:35AM PST, ID: 20970992

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.24.2008 at 01:23PM PST, ID: 20971456

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.25.2008 at 12:33PM PST, ID: 20978924

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.25.2008 at 01:06PM PST, ID: 20979244

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.26.2008 at 12:32AM PST, ID: 20982494

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.26.2008 at 03:30AM PST, ID: 20983262

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.27.2008 at 01:06AM PST, ID: 20992444

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.27.2008 at 02:00AM PST, ID: 20992668

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.28.2008 at 01:01PM PST, ID: 21008009

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.16.2008 at 05:26AM PST, ID: 20909490

Rank: Master

do you have a stacktrace?
 
02.18.2008 at 12:08PM PST, ID: 20923006
source: Microsoft.Practices.EnterpriseLibrary.Data

stack: at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.get_DefaultName() at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name, IConfigurationSource configSource) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, IConfigurationSource configurationSource) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IConfigurationSource configurationSource) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.CreateDefault() at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase() at MyLogger.DBLogger..cctor() in C:\dotnet\MyLogger2\MyLogger\Class1.cs:line 130
 
 
02.19.2008 at 05:44PM PST, ID: 20934341
ok, this is what i have so far.  it appears that the database is created fine, but i am not getting anything written to the db though when i call Write().  thanks.

 

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
    public class DBLogger
    {
        LogWriter writer = null;
        FormattedDatabaseTraceListener logFileListener = null;
        LogSource mainLogSource = null;
        LogSource emptyTraceSource = null;
        TextFormatter formatter = null;
        string sCategory = "";
        Database db = null;
 
        public DBLogger(string sDBServerName, string sDBName, string sUser, string sPasswd, Level level,
            string sMessage, string sMiscellaneous)
        {
            try
            {
                formatter = new TextFormatter("Timestamp: {timestamp}{newline}" +
                    "Message: {message}{newline}" + "Category: {category}{newline}");
 
                emptyTraceSource = new LogSource("none");
 
                // example: data source=arc-tms-db2005;initial catalog=northwind;Integrated Security=SSPI
                string sConnectionString = "data source=" + sDBServerName + "; initial catalog=" +
                    sDBName + ";Integrated Security=SSPI";
 
                db = new SqlDatabase(sConnectionString);
 
                logFileListener = new FormattedDatabaseTraceListener(db,
                    "WriteLog", "AddCategory", formatter);
 
                // adding collection of TraceListeners.
                // LogSource provides tracing services through a set of TraceListeners. 
                switch (level)
                {
                    case (Level.DEBUG):
                        mainLogSource = new LogSource("MainLogSource", SourceLevels.All);
                        sCategory = "Debug";
                        break;
                    case (Level.ERROR):
                        mainLogSource = new LogSource("MainLogSource", SourceLevels.Error);
                        sCategory = "Error";
                        break;
                    case (Level.MESSAGE):
                        mainLogSource = new LogSource("MainLogSource", SourceLevels.Information);
                        sCategory = "Message";
                        break;
                    default:
                        mainLogSource = new LogSource("MainLogSource", SourceLevels.Information);
                        sCategory = "Message";
                        break;
                }
 
                mainLogSource.Listeners.Add(logFileListener);
 
                IDictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
 
                // Add to Category "Error" our EventLog Listener with the corresponding category in it.
                traceSources.Add(mainLogSource.Name, mainLogSource);
 
                writer = new LogWriter(new ILogFilter[0], // ICollection<ILogFilter> filters
                    traceSources, // IDictionary<string, LogSource> traceSources
                    emptyTraceSource, // LogSource allEventsTraceSource
                    emptyTraceSource, // LogSource notProcessedTraceSource
                    mainLogSource, // LogSource mainLogSource
                    "Error", // string defaultCategory
                    false, // bool tracingEnabled
                    true); // bool logWarningsWhenNoCategoriesMatch
            }
            catch (Exception ex)
            {
            }
        }
 
 
        /// <summary>
        /// Writes an Error to the log.
        /// </summary>
        /// <param name="message">Error Message</param>
        public void Write(string message)
        {
            try
            {
                Write(message, sCategory);
            }
            catch (Exception ex)
            {
            }
        }
 
 
        /// <summary>
        /// Writes a message to the log using the specified
        /// category.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="category"></param>
        public void Write(string message, string category)
        {
            try
            {
                LogEntry ent = new LogEntry();
                ent.Categories.Add(category);
                ent.Message = message;
                ent.Severity = System.Diagnostics.TraceEventType.Information;
                writer.Write(ent);
            }
            catch (Exception ex)
            {
            }
        }
 
        public void CloseWriter()
        {
            writer.Dispose();
        }
    }
Open in New Window
 
02.24.2008 at 09:24AM PST, ID: 20970565

Rank: Master

I'm not sure what you try to accomplish here.
You have trouble with the logging block?

If I recall right, you can install the sample database from the sql script that comes with the logging block.
Then use the EL configuration tool with your app.config to add a logging block, and attach a database provider to your category.
Normally you don't have to write so much code for getting database logging done when using the EL.
 
02.24.2008 at 10:33AM PST, ID: 20970757
the management at NASA thinks that it's better if we programmatically configure the DB logging so we can build an interface layer on top of it.  i have no say in this matter.  what you see is a wrapper class around it, and then i have to build an interface on top of that.
 
02.24.2008 at 11:35AM PST, ID: 20970992

Rank: Master

have you added a reference to the microsoft.practices.enterpriselibrary.logging.database?

if you use database logging from the EL, it needs this dll, but it does not add it automatically.
 
02.24.2008 at 01:23PM PST, ID: 20971456
yes, i have attached the whole project and a small tester web page, please take a look at it.  thanks.
 
 
 
02.25.2008 at 12:33PM PST, ID: 20978924

Rank: Master

Ok, I think I found your issue.
change
 traceSources.Add(mainLogSource.Name, mainLogSource);
into
 traceSources.Add(sCategory, mainLogSource);

inside your DBLogger ctor.
The logSources should be associated with a category, which they weren't now.
 
02.25.2008 at 01:06PM PST, ID: 20979244
sorry, i did what you said, and still I don't see a log entry into the DB.
 
source file and tester
 
 
02.26.2008 at 12:32AM PST, ID: 20982494

Rank: Master

I'm on a different machine currently, but another thing that I recall, is that I don't use a formatter for a database logsource (just pass in null)
 
02.26.2008 at 03:30AM PST, ID: 20983262
ok i did this:

logFileListener = new FormattedDatabaseTraceListener(db,
                    "WriteLog", "AddCategory", null);

still not working.  thanks.
 
02.27.2008 at 01:06AM PST, ID: 20992444

Rank: Master

Tonight I can copy/paste the code I used succesfully at home. The change above looks fine to me.
 
02.27.2008 at 02:00AM PST, ID: 20992668
in that case, i will wait for you next post.  thanks.
 
02.28.2008 at 01:01PM PST, ID: 21008009

Rank: Master

I just checked the code which is running without any problems on my machine, and it's the same like yours after the fix.

I have used the LoggingDatabase.sql script that comes with the EL and installed it on a SQL express instance.

I then called your code like :
baseLogging.LogToDB("localhost\\sqlexpress", "Logging", "", "", Level.DEBUG, "LogToDB", "");
same like you did in your zip file.
and it works on my machine.
are you sure you can connect to your database with the passed connectionstring?

you can:
  db = new SqlDatabase(sConnectionString);
DbConnection conn = db.CreateConnection();
conn.Open();
see what that does...
Otherwise.. I dunno..
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
 public DBLogger(string sDBServerName, string sDBName, string sUser, string sPasswd, Level level,
            string sMessage, string sMiscellaneous)
        {
            emptyTraceSource = new LogSource("none");
 
            // example: data source=arc-tms-db2005;initial catalog=northwind;Integrated Security=SSPI
            string sConnectionString = "data source=" + sDBServerName + "; initial catalog=" +
                sDBName + ";Integrated Security=SSPI";
 
            db = new SqlDatabase(sConnectionString);
 
            logFileListener = new FormattedDatabaseTraceListener(db,
                "WriteLog", "AddCategory", null);
 
            // adding collection of TraceListeners.
            // LogSource provides tracing services through a set of TraceListeners. 
            switch (level)
            {
                case (Level.DEBUG):
                    mainLogSource = new LogSource("MainLogSource", SourceLevels.All);
                    sCategory = "Debug";
                    break;
                case (Level.ERROR):
                    mainLogSource = new LogSource("MainLogSource", SourceLevels.Error);
                    sCategory = "Error";
                    break;
                case (Level.MESSAGE):
                    mainLogSource = new LogSource("MainLogSource", SourceLevels.Information);
                    sCategory = "Message";
                    break;
                default:
                    mainLogSource = new LogSource("MainLogSource", SourceLevels.Information);
                    sCategory = "Message";
                    break;
            }
 
            mainLogSource.Listeners.Add(logFileListener);
 
            IDictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
 
            // Add to Category "Error" our EventLog Listener with the corresponding category in it.
 
            traceSources.Add(sCategory, mainLogSource);
 
 
            writer = new LogWriter(new ILogFilter[0],  // ICollection<ILogFilter> filters
                traceSources, // IDictionary<string, LogSource> traceSources
                emptyTraceSource, // LogSource allEventsTraceSource
                emptyTraceSource, // LogSource notProcessedTraceSource
                mainLogSource, // LogSource mainLogSource
                "Error", // string defaultCategory
                false, // bool tracingEnabled
                true); // bool logWarningsWhenNoCategoriesMatch
            Debug.Write(writer.IsLoggingEnabled());
        }
Open in New Window
Accepted Solution
 
 
02.28.2008 at 01:58PM PST, ID: 21008620
thanks.  just wondering, does ELL support concurrency (for logging to DB, files, etc), or do i have to account for that in my code?
 
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628