Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

DatabaseFactory.CreateDatabase() method

Back to Forum: Tech Off
  • User profile image
    MadTurtle

    I have a very simple program where I am taking an XML feed from a DB and writing it to a file.  I am using the Enterprise Library to create the DB connection and everything is candy and roses. 

    However, I have been asked to give the users the ability to define the DB through one of the arguements passed in as the connection string and that is where I run into this problem. 

    When I try to use the 0 argument method (DatabaseFactory.CreateDatabase()) instead of one where I pass in the name of my Database (DatabaseFactory.CreateDatabase("MyDBName")), which is defined in my App.config file, the method call throws an exception with the message "The value can not be null or an empty string."

    It seems to me that I should be able to call this method to create a Database object and then set its properties afterwards, and in fact it was suggested that I do this by two people I respect as knowledgeable individuals, but for some reason I am unable to do so.  

    I assume this is just some type of configuration issue with my App.config file but a dozen Google searches have turned up nadda.  Has anyone out there run into this type of issue before?  

  • User profile image
    LiquidSpy

    Is it possible to use a generic database name and just change the connection string in the app.config programmatically? Just a thought.

  • User profile image
    jb43081

    MadTurtle wrote:
    I have a very simple program where I am taking an XML feed from a DB and writing it to a file.  I am using the Enterprise Library to create the DB connection and everything is candy and roses. 

    However, I have been asked to give the users the ability to define the DB through one of the arguements passed in as the connection string and that is where I run into this problem. 

    When I try to use the 0 argument method (DatabaseFactory.CreateDatabase()) instead of one where I pass in the name of my Database (DatabaseFactory.CreateDatabase("MyDBName")), which is defined in my App.config file, the method call throws an exception with the message "The value can not be null or an empty string."

    It seems to me that I should be able to call this method to create a Database object and then set its properties afterwards, and in fact it was suggested that I do this by two people I respect as knowledgeable individuals, but for some reason I am unable to do so.  

    I assume this is just some type of configuration issue with my App.config file but a dozen Google searches have turned up nadda.  Has anyone out there run into this type of issue before?  


    Turtle,

    Make sure that you use the Configuarion Tool that ships with Enterprise Library to define your default connection. The markup this puts in the config file is different than you would normally use, and I don't think the database section of Enterprise Library can find it without that markup.

    Good luck!

  • User profile image
    MadTurtle

    LiquidSpy wrote:
    Is it possible to use a generic database name and just change the connection string in the app.config programmatically? Just a thought.


    At one point I tried this as a possible solution but received the message that the attribute was readonly.  I did not spend a great deal of time trying to get this to work though so if you have an example of how to modify the connectionString attribute of the app.config file I would be happy to give it a shot.

  • User profile image
    MadTurtle

    jb43081 wrote:
    Turtle,

    Make sure that you use the Configuarion Tool that ships with Enterprise Library to define your default connection. The markup this puts in the config file is different than you would normally use, and I don't think the database section of Enterprise Library can find it without that markup.

    Good luck!


    jb43081,

    I am looking into this now but it should be noted that when I use the DatabaseFactory.CreateDatabase() method with the 'default' name passed it is able to create a database object without error.  It is only when I use the 0 argument method that it has problems.  I will Google the Config Manager and see if that offers any solutions. 

    Thanks,

    MadTurtle

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.