ConnectionString

Stimulsoft Reports.NET discussion
mansourweb
Posts: 13
Joined: Sat Aug 29, 2009 2:42 pm

ConnectionString

Post by mansourweb »

Dear Friends,

I have a report in c# windows application that its connectionstring is Password=123;Data Source=pc1\MAHMADI;Integrated Security=False;Initial Catalog=Commision;User ID=mahmadi in STIMULSOFT environment.

In c# i use the following code:


sr = (StiReport)report1.Clone();
sr.DataStore.Clear();
sr.RegData("Commision", "Password=123;Data Source=pc2\MAHMADI;Integrated Security=False;Initial Catalog=Commision;User ID=mahmadi");
sr.Compile();

sr.Show();

when i change the connectionstring from c# like above, it doesn't affect on the main report.

would you please direct me how change the name of pc that sql server installed, in connectionstring from c#?

in advanced, Thank you for your kindness.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

ConnectionString

Post by Alex K. »

Hello,

You can see the article on our knowledgbase
http://stimulsoft.helpserve.com/index.p ... ticleid=15

Thank you.
mansourweb
Posts: 13
Joined: Sat Aug 29, 2009 2:42 pm

ConnectionString

Post by mansourweb »

Dear Aleksey,

Thank you for your attention and response.

I add these two lines :

sr.Dictionary.Databases.Clear();
sr.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Commision", newConnectionString));

but it only show me empty report.
I have a table in my report. I thought , i must add table to sr.dictionary.database, but i don't know HOW?

would you please help me?

thank you.
mansourweb
Posts: 13
Joined: Sat Aug 29, 2009 2:42 pm

ConnectionString

Post by mansourweb »

How can I change my connectionstring please ????

in my report , i use connection and datasource.
in connectionstring, my Data Source is pc2\MAHMADI , so if i install my software in the computer, i must change the datasource. how can i change it from C# code ??

Really thank you for your responses
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

ConnectionString

Post by Alex K. »

Hello,

You can use the following code.
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.
mansourweb
Posts: 13
Joined: Sat Aug 29, 2009 2:42 pm

ConnectionString

Post by mansourweb »

Dear Aleksey,

Thank you for your response. I wrote the following codes as you said. At first, I copy from my designed report, clear its previous database and add new one. it doesn't occur any errors but it show me empty error.

How i can fix it?
Really thank you.

Code: Select all

       StiReport sr = new StiReport();

                sr = (StiReport)nameersali.Clone();
                sr.Dictionary.Databases.Clear();

                string cs = @"Password=12343;Data Source=mansourpc\mahmadi;Integrated Security=False;Initial Catalog=Commision;User ID=mahmadi;";

/////////////////////////////////////////////////////////////////////////////////////

                sr.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Commision", cs));

                Stimulsoft.Report.Dictionary.StiSqlSource DS1 = new Stimulsoft.Report.Dictionary.StiSqlSource("Commision", "student", "student", "SELECT * FROM student",          true, false);
                sr.Dictionary.DataSources.Add(DS1);

/////////////////////////////////////////////////////////////////////////////////////

                DataTable dataTableDS1 = DAL.qycustom("Select * from student");

                foreach (DataColumn col in dataTableDS1.Columns)
                {
                    DS1.Columns.Add(col.ColumnName, col.DataType);
                }

                sr.Show();
mansourweb
Posts: 13
Joined: Sat Aug 29, 2009 2:42 pm

ConnectionString

Post by mansourweb »

Yes, Thank you Very Much. I change the code as below:


Code: Select all

StiReport sr = new StiReport();

                sr = (StiReport)nameersali.Clone();
                sr.Dictionary.Databases.Clear();
                sr.Dictionary.DataSources.Clear();
                sr.DataSources.Clear();

                string cs = @"Password=1234;Data Source=mansourpc\mahmadi;Integrated Security=False;Initial Catalog=Commision;User ID=mahmadi;";

                sr.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("Commision", cs));

                Stimulsoft.Report.Dictionary.StiSqlSource DS1 = new Stimulsoft.Report.Dictionary.StiSqlSource("Commision", "Student", "Student", "SELECT * FROM    student", true, false);
                sr.Dictionary.DataSources.Add(DS1);

                ///////////////////////////////////////////////////

                DataTable dataTableDS1 = DAL.qycustom("Select * from student");

                foreach (DataColumn col in dataTableDS1.Columns)
                {
                    DS1.Columns.Add(col.ColumnName, col.DataType);
                }


                sr.Show();
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

ConnectionString

Post by Alex K. »

Hello,

Does this mean that the issue is solved?

Thank you.
mansourweb
Posts: 13
Joined: Sat Aug 29, 2009 2:42 pm

ConnectionString

Post by mansourweb »

Hi,

Yes, Thank you :biggrin:

in the line below:
Stimulsoft.Report.Dictionary.StiSqlSource DS1 = new Stimulsoft.Report.Dictionary.StiSqlSource("Commision", "Student", "Student", "SELECT * FROM student", true, false);

i used student with small s, as in my designed report, it is with capital S. i change the student here with Student, and use your code and SOLVE.

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

ConnectionString

Post by Alex K. »

Hello,

We are always glad to help you!
Let us know if you need any additional help.

Thank you.
Post Reply