How to specify connection string without using DBUtils

Posts   
 
    
olegy
User
Posts: 2
Joined: 26-Mar-2005
# Posted on: 26-Mar-2005 02:38:24   

I'm new with llblgenpro product. So, excuse me for the silly question. I need to assign a connection string without using DBUtils but using interface approach - the assembly with DBUtils is not available for me at design time - not referenced - as a part of design.


ObjectDiscovery od = new ObjectDiscovery(className,assembly); // custom code
IEntityCollection cc = od.GetEntityCollection(); // custom method to get IEntityCollection
// here is my problem - how to pass a connection to the cc object
cc.GetMulti(null, 100000, null, null, 0, 0); // breaks if no connection set
Data.DataTable dt = new Data.DataTable();
if(cc.Count>0)
  {
    IEnumerable ienum=  cc as IEnumerable;
    IEnumerator ie =ienum.GetEnumerator();
    ie.MoveNext();
    IEntity ce = (IEntity)ie.Current;
    IEntityFields fields = ce.Fields;
    for(int i=0;i<fields.Count;i++)
        {
            IEntityField field = fields[i];
            dt.Columns.Add(field.Name,field.GetType());
        }
    ie.Reset();
    while( ie.MoveNext())
    {
                    IEntity cei = (IEntity)ie.Current;
        IEntityFields fields_a = cei.Fields;
        Data.DataRow dr= dt.NewRow();
        for(int i=0;i<fields_a.Count;i++)
                        {
                IEntityField field_a = fields_a[i];
                dr[field_a.Name]=field_a.CurrentValue;
            }
        dt.Rows.Add(dr);

    }
}

It breaks here:


// here is my problem - how to pass a connection to the cc object
cc.GetMulti(null, 100000, null, null, 0, 0); // breaks if no connection set 

Any help would be helpfull. Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 26-Mar-2005 10:09:37   

You should specify the connection string in the .config file of your application (be it a web.config or app.config file). See Using the generated code -> Compiling the code in the documentation.

Frans Bouma | Lead developer LLBLGen Pro
olegy
User
Posts: 2
Joined: 26-Mar-2005
# Posted on: 28-Mar-2005 20:51:37   

Otis wrote:

You should specify the connection string in the .config file of your application (be it a web.config or app.config file). See Using the generated code -> Compiling the code in the documentation.

That is the problem - I'm using MS Report Services. That the type of the project, where there is no app.config file could be used ( I'm talking about the designer part of the project) Any attempts to add and use the connection string section to ALL possible config files have failed. What other options I could have?

The only way I was able to do it - reflection:


......
System.Type[] ExistingTypes = workingAssembly.GetTypes(); 
System.Type type = null;
System.Type dbUtilsType =null;
foreach (Type tp0 in ExistingTypes)
                if(tp0.Name.ToLower()=="dbutils")
    {
        dbUtilsType =tp0;
        break;
    }
}   
if (dbUtilsType== null)
{
    throw new System.Exception("Object not found");
}
try 
{
    FieldInfo finfo=dbUtilsType.GetField("ActualConnectionString");
    finfo.SetValue(dbUtilsType,@"data source=....");
}
catch (Exception e)
    Debug.WriteLine(e.Message);
} 

But it is not elegant. I'd rather had an interface method to work with.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Mar-2005 10:36:11   

In SelfServicing, it's a static property, so an interface won't work. In Adapter you could pass on the connection string to the DataAccessAdapter instance.

Frans Bouma | Lead developer LLBLGen Pro