Really Sorry for the N00b Question

Topics: Data Access Application Block
Dec 22, 2010 at 9:41 PM

Hi folks:

I sincerely apologize for this n00b question.

So today, I installed the Enterprise LIbrary 5.0 on my development machine.

I created a new VS2010 winforms application, set it to .net 4.0.

I set the reference in my project to Microsoft.Practices.EnterpriseLibrary.Common, Data, Unity, and ServiceLocation.

I added a new app.config file to the project. I right-clicked on it in solutions explorer, and chose "Edit Enterprise Library 5.0 Configuration"

I added a data settings application block. In there, there is a database setting for LocalSQLServer that appears in my machine.config that connects to a local instance of MSSQL Express.

In this new database settings section, i add a database instance. I give it a name "MySampleDB", i set the connection string, and chose SQLClient as the provider. I save and exit. I can see the settings in the app.config file that is in my project.In my Windows Form, I add a button and an on_click event. In that code, I'm doing this:

Database

 

MySampleDB = EnterpriseLibraryContainer.Current.GetInstance<Database>("MySampleDB");

 I compile. There are no errors.

when I step into this, click on the button, an error gets thrown:

 

Locating source for 'c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs'.

 

(No idea who Chris is, btw. it's not me).

I'm obviously missing something pretty basic but can't figure it out.

I came across this Enterprise Library when trying to find a Data Access Layer framework to avoid having to hand-code common DB functions to an MS SQL 2008 DB using C#.

This Enterprise LIbrary Data Access Application block looks almost like what could be very useful.

I do not understand why I am unable to even get started with that simple line above. If i cannot get connected to the DB, then obviously, the rest of the DAAB cannot execute.

I'm beside myself with frustration in not figuring this out. I do not quite understand why LocalSQLServer is stored in the machine config, along with it's connectionString. It does work.

but what i'm needing to do is specify the connectionstring and DB settings to go along with my applicaiton at an application, not machine level.

I'm REALLY REALLY sorry for being so n00bish. This is my first time with DAAB and the 5.0 library. Looks awesome. but can't get off the ground.

How can I tell the Enterprise LIbrary that i'm using an app.config in my project, not some global machine.config?

Dec 23, 2010 at 2:55 AM

Hi,

First, the LocalSQLServer database instance under you DAAB configuration is by default included as part of the DAAB config. The connection string is defined in the machine.config file, and is inherited by your app's config file. This is by design expected in the DAAB config though you can just ignore this and instead create your own database instance/connection string.

As for the "Locating source for 'c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs'." this will really happen since you're trying to step into the DAAB code and need to properly locate where the source code is located. If you really would like to step into the DAAB code what you can do is from the VS2010 No Source Available Page, click the Browse to Find Source linkbutton and locate to the exact location of the EntLib Source Code.

Anyway, I think there is really no problem on how you have started with DAAB. Your observations is just expected (unless you're already encountering any exception raised you haven't mentioned from your post). What I can suggest to you right now is just continue on with utilizing your Database object and do stuff you would want to do with it. Btw, you can also try Entlib's Hands-On Lab and Dev Guide if you would want to learn more about EntLib. Hope this helps.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Dec 23, 2010 at 4:13 AM

By the way, I'm Chris. That DLL was compiled on my machine, so the paths in the .pdb file are pointing to the directory it was built in. By default, Visual Studio will try to look in the path given in the PDB file for source code when you step into.

Are you getting an exception and it's looking for source code, or are you just trying to step into the internals? I would strongly recommend you step over this line, though, rather than trying to step into. The Entlib source is rather complex about getting things wired up, and you won't really gain any useful knowledge about the basics of using the data block from trawling through the guts.

If you're actually getting an exception, on the other hand, posting the exception details will make it a lot easier to help resolve your issue, whatever it might be.

 

 

Dec 23, 2010 at 1:39 PM

Hi All:

Here's my config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
  <dataConfiguration defaultDatabase="MySample" />
  <connectionStrings>
    <add name="MySample" connectionString="Data Source=FSE1\sqlexpress2008r2;Initial Catalog=SigmaGW2011_DEV;Persist Security Info=True;User ID=sa;Password=*****"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <typeRegistrationProvidersConfiguration>
    <remove name="Data Access" />
    <add name="Data Access" providerType="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSyntheticConfigSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    <remove name="Validation" />
    <add name="Validation" providerType="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationTypeRegistrationProvider, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </typeRegistrationProvidersConfiguration>


</configuration>
And here's the line of code that i'm having problems with:
Database MySampleDB = EnterpriseLibraryContainer.Current.GetInstance<Database>("MySample")
That line triggers the error: 
{"Activation error occured while trying to get instance of type Database, key \"MySample\""}
{"Resolution of the dependency failed, type = \"Microsoft.Practices.EnterpriseLibrary.Data.Database\", name = \"MySample\".\r\nException occurred while: while resolving.\r\nException is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.\r\n-----------------------------------------------\r\nAt the time of the exception, the container was:\r\n\r\n  Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,MySample\r\n"}
I have my project on a local drive, D:\myproject
I have an app.config specified in the project, editited using the Enterprise Configuration Manager.
My database is running, and that specified connectionstring works with traditional code.
Again, I must apologize for such a basic question. I've read everywhere. the book, Developer's Guide to Microsoft Enterprise Library 5 says that if there's no Configurations Section, that it will default to the application config file.
I'm so frustrated that I cannot figure out why I can't get my engine started with this. I'm stuck at go. If I can overcome this hurdle, then perhaps I can finally start using the code to execute stored procs and such for my appl.
but i cannot get past this after two ddays of effort. Why won't it load and set a reference to "MySample"? What am I doing wrong? It's got to be something so stupidly simple.
Dec 23, 2010 at 2:21 PM

Guys, I figured it out.

 

My Sample VS 2010 Solution had two projects, a class library (DLL) and a Windows Form App.

My windows form app was instantiating an object in my class libary. My class library was trying to use the Enterprise Framework 5.0 and I had the app.config in the wrong project. Honestly, I did not know that class libraries (DLLs) cannot reference app.config.

I moved my app.config to the WIndwos Form and it works fine.

So I was able to connect to my DB.

I *DID* make a n00b mistake, though it had nothing really to do with the framework. I should have remembered that Class Libraries cannot use app.config settings.

 

Jul 17, 2012 at 9:51 PM

So, to bring this back up.  I have attempted the same thing.  I am attempting to run the Security sample application.   It successfully builds, however when running the application it stops at the first line of Program.cs:

secCache = EnterpriseLibraryContainer.Current.GetInstance<ISecurityCacheProvider>("CacheProvider"); 

and quits working displaying the message box, Microsoft is searching online for a solution.  This same exception actually appears to be thrown at each of these lines:

ruleAuth = EnterpriseLibraryContainer.Current.GetInstance<IAuthorizationProvider>("RuleProvider");         

azmanAuth = EnterpriseLibraryContainer.Current.GetInstance<IAuthorizationProvider>("AzManProvider");

When attempting to run in debug a new code editor window comes up with a message of "No Source Available" and it refers to the location in Chris's directory mentioned above, and the options of "Browse For File" or "Show Disassembly" are given.

If screen clips would help, sorry.

Anyways, some insight would be appreciated.  Thanks.

Jul 17, 2012 at 10:38 PM

To be blunt, it appears as though the project has quite a few inconsistencies.  See this post for some of the issues: https://entlib.codeplex.com/discussions/261653.  

To me it looks the sample application is referencing inconsistent versions of Enterprise Library.  The Enterprise Library assemblies are 5.0.505.0 but the the Unity assemblies are 2.0.414.0.  The Unity version for Enterprise Library 5.0.505.0 should be 2.0.505.0.  Also, the configuration file is referencing Enterprise Library 5.0.414.0 which is different than the assembly references.

Since I have Enterprise Library 5 Optional Update 1 (Version 5.0.505.0) installed what I did was:

  1. Update the reference for Microsoft.Practices.Unity and Microsoft.Practices.Unity.Interception to be version 2.0.505.0 (the assemblies installed along with Enterprise Library 5.0.505.0)
  2. Modified the app.config to change all references 5.0.414.0 to 5.0.505.0
  3. Changed the location of the Azman storeLocation in the app.config from "msxml://C:\EntLib\EntLib5\Guides\DevGuide\Dual Language Version\Code Samples\Code-CS\Security\Security\Example.xml" to the location based on my installation directory.
  4. Changed the location of the protectedKeyFilename from "D:\Chris\Projects\Entlib\V5\Docs\Guides\DevGuide\C# Version\Code Samples\Security\Security\cctkey.key" to my local installation directory and created a key file as per the documentation.

After that the sample app was able to run.  Hope that helps.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jul 18, 2012 at 12:19 AM

Whew, and wow, anyways, thanks for the help Randy.

So far I have updated the references to Unity and Unity.Interception to 2.1.505.0 because it is all I could get other than 2.0.414.0 from the 3 downloads I've unpacked and installed so far, which I got from http://www.microsoft.com/en-us/download/details.aspx?id=15104.  

I left the app.config references to 5.0.414.0 because I noticed that is the version of the assemblies referenced in the project, I also attempted with references updated to 5.0.505.0 in case something out of the ordinary that did not make sense were to happen (which can happen sometimes, correct?).

I've updated the Azman storelocation in the app.config to my local location as well as updated the protectedKeyFilename location from Chris's directory to the local directory Samples/Security/Security/examplekey.key where the example key distributed with the project is located.  The Security/Security directory structure created is due to the upgrade process from a Visual Studio 2008 solution to Visual Studio 2010 solution.  If attempting to use the Enterprise Library in Visual Studio 2008 solves the entire issue I will know at a later time when on machine at home with Visual Studio 2008.

Anyways, still same exception.

Jul 18, 2012 at 4:34 AM
Edited Jul 18, 2012 at 4:50 AM

As I said, it looks like the issue is with the references/assembly versions.  From the link you downloaded Enterprise Library 5.0.414 which is not the latest the latest is Enterprise Library Optional Update 1 build version 5.0.505.0 which you can download here or via Nuget.

You could try removing all of the assembly references and downloading the appropriate packages from NuGet.  It works for me to remove the existing references and download the following Nuget packages:

  • Security Application Block AzMan Authorization Provider
  • Caching Application Block Cryptography Provider
  • Security Application Block Caching Store

Then update the config file to reference the latest version (5.0.505.0).

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jul 21, 2012 at 7:39 PM

Although I am getting things moving, some thanks to you Randy, any further work or description of where I am with this is beyond the scope of a message board.  Thank again, I am very interested in supporting this Microsoft open source movement.