Page 1 of 1
DSN LESS ODBC Connection
Posted: Mon Nov 15, 2010 12:29 am
by dikan
I have DSN LESS connection in my application and I tried to make that kind of connection when I run my reports but I am obviously doing something wrong.
If I put connection string from my application into SQL connection through designer and it works well.
I played with report.Dictionary.Database.Clear and report.Dictionary.Database.Add(StiODBCDatabase(Database,ConString)) but with no luck.
So, my question is how to dynamically change connection string for ODBC or any other connection.
Regards,
Djole
DSN LESS ODBC Connection
Posted: Mon Nov 15, 2010 1:01 am
by Alex K.
Hello,
If you add a connection to the dictionary in the code, and invoke the report.Dictionary.Database.Clear() method, you need to add other elements of the dictionary - tables, columns, relations.
New connection string:
Code: Select all
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Connection", newConnectionString));
Add DataSources:
Code: Select all
StiSqlSource DS1 = new StiSqlSource("Connection", "DS1", "DS1", "SELECT * FROM DS1", true, false);
report.Dictionary.DataSources.Add(DS1);
Add Columns:
Code: Select all
foreach (DataColumn col in dataTableDS1.Columns)
{
DS1.Columns.Add(col.ColumnName, col.DataType);
}
Add Relations:
Code: Select all
StiDataRelation dataRelation = new StiDataRelation("MyRelation", parentDS, childDS, new string[] { "Field" }, new string[] { "Field" });
report.Dictionary.RegRelations();
report.Dictionary.Relations.Add(dataRelation);
Thank you.
DSN LESS ODBC Connection
Posted: Mon Nov 15, 2010 1:35 am
by dikan
Yes, I understand that, but I do not want to change dictionary and set all these staff in already defined dictionary. I want just to change connection string. I tried with variable as DSN settings but it does not work.
Can you give me example for changing connection string?
Regards,
Djole
DSN LESS ODBC Connection
Posted: Mon Nov 15, 2010 8:07 am
by dikan
Never mind. I solved this.
DSN LESS ODBC Connection
Posted: Mon Nov 15, 2010 2:41 pm
by Andrew
Ok!
Have a nice day!
Thank you.