Jump to content

External Connection Strings?

3 replies to this topic

#1 Guest_John Henkel_*

Guest_John Henkel_*
  • Guests

Posted 11 January 2005 - 09:42 AM

In the documentation, it mentions that connect strings can be in a config file, but it doesn\'t say how to do this?

So how do you put a connect string in an external file that TD references?

#2 Guest_Paul_*

  • Guests

Posted 11 January 2005 - 09:54 AM


TierDeveloper handles connection string differently depending on the type of components you have built. If you have generated .NET components for COM+, then you can go to "component services" and specify a different connection-string for the "activation-string" property of the components. By default, factory classes use hard coded connection strings to access database in case you donít specify it through COM+.

In case of NON GAC/NOT MTC components, TierDeveloper provides constructor in factory classes so that one can pass custom connection string. You can either use a hard coded connection string or you can provide the connectoin information in the Project Config file and can use it dynamically.

To specify the Connection String, for .NET components, via project config file you need to follow these steps.
  • Generate & Build Non NonGAC/NonMTS components from the TierDeveloper.
  • Open the file PROJECTNAME.dll.Config (PROJECTNAME is the name of your TierDeveloper project) where the components are generated and edit your own Connection String or modify the existing one.
  • Open the component files in the any Editor of your choice e.g., .NET IDE
  • Add the following lines of code in the default constructor of factory class
    for example
    public ProductFactory():base("Provider=SQLOLEDB;server=localhost;User Id=sa; Password=", TDevFramework.EDBProvider.OLEDB))
    base.DBProvider = TDevFramework.EDBProvider.OLEDB;

    rebuild the components. It will work.

#3 Guest_abpeterson_*

  • Guests

Posted 28 July 2005 - 09:12 AM

Issue with this, if I rebuild the project, it overrides it. There should be a feature to add that in web.config inside TierDeveloper.

#4 Guest_Paul_*

  • Guests

Posted 29 July 2005 - 10:24 AM

Yet, another way to achieve this solution is to modify the existing template so that it can generate code that can read the connection information from the config file. This way no matter how many times you rebuild the code, it will always read the data source information from the Config file. And, with a single change in the config file (outside the code) your components will point to a new data source and you donít have to rebuild the code at all.

Here is how you can modify the factory template
  • Go to the folder installation folder "Patterns\PrePackaged\CSComponent\Source\Components" and open the file "ComponentFactory_cs"
  • 2. Change the factory default constructor as given below
    public <%=CurrentObject.Name%>Factory() : base(<%if(!bInherited){%>ConfigurationSettings.AppSettings["Object.<%=CurrentObject.Name%>"], <%=libType%><%}%>)
  • 3. Done! Now generate and build the components. After successfully generated the code, copy PROJ.dll.Config file to your applicationís bin folder.
  • 4. Run the application and it will use connection string information provided in the Config file.
If you have TierDeveloper 5.0 you can do the above changes using Template IDE and can clone the existing templates to extend the existing functionality.

I hope it helps solve your situation

Reply to this topic


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users