DSN LESS ODBC Connection

Stimulsoft Reports.NET discussion
Post Reply
dikan
Posts: 202
Joined: Thu Jun 18, 2009 5:05 pm
Location: Serbia

DSN LESS ODBC Connection

Post 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

Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

DSN LESS ODBC Connection

Post 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.
dikan
Posts: 202
Joined: Thu Jun 18, 2009 5:05 pm
Location: Serbia

DSN LESS ODBC Connection

Post 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
dikan
Posts: 202
Joined: Thu Jun 18, 2009 5:05 pm
Location: Serbia

DSN LESS ODBC Connection

Post by dikan »

Never mind. I solved this.
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

DSN LESS ODBC Connection

Post by Andrew »

Ok!

Have a nice day!
Thank you.
Post Reply