PDA

Click to See Complete Forum and Search --> : Problem with ConnectionProperties


korax
Jan 5th, 2008, 05:27 AM
Hey.
Sory for C#...

I have report created in CR 11 Pro:

In Database -> Set datadource location:


MyServer\sql_2005
-> Properties
Database Type: ODBC (RDO)
Connection String: DRIVER={SQL Server};SERVER=MyServer\sql_2005;DATABASE=CRDataBase
User ID: MyUser
Database: CRDataBase
SERVER: MyServer\sql_2005
Use DSN Default Properties: False

and for each table like this:

-> Magazyny
-> Properties
Table Name: Magazyny
Table Type: Tables
Catalog: CRDataBase
Owner: MyUser


Setting: Save data with Report = off

Ok. I try to use this file in crystal viewer control.



crReport = crApp.OpenReport(@"C:\Raport1.rpt", 1);

crReport.DiscardSavedData();

k_Viewer.ReportSource = crReport;
k_Viewer.ViewReport();



And the report run fine but when i change (in SQL Server Management Studio) the name of database from CRDataBase to XDataBase i have error:

System.Runtime.InteropServices.COMException (0x80047E48): Logon failed.
Details: 01S00:[Microsoft][ODBC SQL Server Driver]Invalid connection string attribute.

Logon failed couse database name has changed.

so a try to change connection string for each tables:
full code:

crReport = crApp.OpenReport(@"C:\Raport1.rpt", 1);

crReport.DiscardSavedData();

for (int i = 1; i < crReport.Database.Tables.Count; i++)
{
crReport.Database.Tables[i].ConnectionProperties.DeleteAll();
crReport.Database.Tables[i].ConnectionProperties.Add("Connection String", @"Driver=SQL Server;Server=" + _Server + ";Database=" + _DataBase + ";UID=MyUser;PWD=");
}

k_Viewer.ReportSource = crReport;
k_Viewer.ViewReport();



and the next error:

System.Runtime.InteropServices.COMException (0x80047E44): The table '' could not be found.

what the ... ?? :mad:

ok.. i try to change database name to old "CRDataBase" and all run fine.
so a created new database with name "CRNew" withe the same structures as "CRDataBase".

report run fine but data was loaded from old database.

so i try to change location of all tables:
full code:


crReport = crApp.OpenReport(@"C:\Raport1.rpt", 1);

crReport.DiscardSavedData();

for (int i = 1; i < crReport.Database.Tables.Count; i++)
{
String oldLocation = crReport.Database.Tables[i].Location;

crReport.Database.Tables[i].ConnectionProperties.DeleteAll();
crReport.Database.Tables[i].ConnectionProperties.Add("Connection String", @"Driver=SQL Server;Server=" + _Server + ";Database=" + _DataBase + ";UID=MyUser;PWD=");

String newLocation = _DataBase + "." + "MyUser" + "." + oldLocation;
crReport.Database.Tables[i].Location = newLocation;

}

k_Viewer.ReportSource = crReport;
k_Viewer.ViewReport();



and data from new database was loaded...

ok.. at the and i delete the old database "CRDataBase" i **** the same error:

System.Runtime.InteropServices.COMException (0x80047E44): The table '' could not be found.

what the... ??

what is with this report ??
why after the changing connection string report do not work on other database??

what else i must do ?

2 fu*** day and nothing..

i must figure this today...

Cristian
Jan 29th, 2008, 08:16 AM
Why you don't try with active data. You only set the setdatasource property to an valid recordset and it will works!!

brucevde
Jan 29th, 2008, 09:58 AM
Its been a very very long time since I did any C coding and may not remember how the For loop works.

But aren't you missing the last table. Shouldn't it be looping from 1 to Count.

for (int i = 1; i <= crReport.Database.Tables.Count; i++)