CodeSmith Template- Database Property Name

CodeSmith Template- Database Property Name

Old forum URL: forums.lhotka.net/forums/t/1817.aspx


WyattRidesAgain posted on Wednesday, November 22, 2006

When I generate code I'm getting output like the following:

  protected override void DataPortal_Insert()
  {
   using (SqlConnection cn = new SqlConnection(Database.C:\_APPS\PROJECTTRACKER20CS\DATA\PTRACKER.MDFConnection))
   {
    .....

... in which the db connection string is appended to "Database."  Instead of the db connection string, should this actually be the name of the property in the static class Database that holds the connection string?  In other words, should the generated output instead be something like:

  protected override void DataPortal_Insert()
  {
   using (SqlConnection cn = new SqlConnection(Database.PTrackerConnection)
   {
    .....

I'm probably missing something or doing something wrong, so any help would be appreciated.

Thx,

Wyatt

JoeFallon1 replied on Wednesday, November 22, 2006

Yes.

You should only read the connection string in one place in your project. Then all of your code can refer to it as you described. Then if you edit your config file the rest of your code works as expected without having to do a massive search and replace and re-compile.

Joe

 

WyattRidesAgain replied on Wednesday, November 22, 2006

Sorry for my poorly worded question;  let me clarify.  In using the CodeSmith templates the output they generate includes the actual connection string, whereas I want to output the name of the property in the Database class containing the pointer to the web.config or app.config file containing the connection string.

Am I using the CodeSmith templates incorrectly or could there be a bug?

Wyatt

Michael Hildner replied on Wednesday, November 22, 2006

Hey Wyatt,

I don't think it's either. I haven't really dug deep into it, but as far as I know, it's the way that CodeSmith itself pulls the database name from the connection string.

Search/replace might be the easiest thing.

Mike

JoeFallon1 replied on Wednesday, November 22, 2006

The Codesmith templates are very good but not perfect.

You should simply edit them to meet your needs.

My own templates are very specific to the rest of my framework. e.g. I have a Data Access Layer code library which is used in my BOs so my templates use my DAL to Fetch/Insert/Update/Delete data.

Or contact the developers (Ricky Supit among others) and suggest modifications.

Joe

 

WyattRidesAgain replied on Monday, November 27, 2006

Joe and Mike,

Thanks for good input.  I've been hoping not to have to dig into the Codesmith templates but maybe I'll need to.  Also, I'll contact Ricky, just in case there's a bug.

Wyatt

 

Copyright (c) Marimer LLC