This is a migrated thread and some comments may be shown as answers.

Reporting Connection String error - unable to connect to database

5 Answers 845 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 2
Sam asked on 08 Feb 2011, 01:54 AM
I am having a problem with the Telerik report when my application is being installed on clients.

The setup: Telerik Report v 921 - VS Studio 2008 .NET 2008 Winforms

A Telerik report with 4 chart controls connected by 4 different Telerik.Reporting.SQLDatasource

The connection strings are set in the connection string property manually.

Property: ConnectionString
server=myserver;User Id=User;password=pwd;database=dbname;Persist Security Info=True
Property: Provider (from drop down)
MySQL.Data.MySqlClient

Now setting the connection strings this way does not write to the app.config file.

On the Constructor of the report, after InitializeComponent() the Telerik.Reporting.SQLDatasource properties are being set to the correct ConnectionString ...

The debug version from development PC works fine. But after making a release and installing the application ...

"Unable to connect to database. Please verify that your connection string is valid...."
 
Any help is much appreciated.

Regards,
Sam



5 Answers, 1 is accepted

Sort by
0
Sam
Top achievements
Rank 2
answered on 08 Feb 2011, 02:24 AM
An update to the post ...

After the initial report design, I had changed my Test Database. But from the design mode now, if I do a Preview / HTML Preview, I see that the Chart1 still thinks it needs to connect to the old database. It still tries to connect to the old IP. Now I cannot find this old IP in code anywhere. Where can I remove this IP from the Charts' properties.

Regards,
Sam
0
Steve
Telerik team
answered on 08 Feb 2011, 12:50 PM
Hello Sam,

Generally when you're using our SqlDataSource Component to connect to data, you do not need to provide connectionString in the report constructor, as by default it is stored in the application settings. This is what the Report and Data Source Wizards actually do when instructed to save the selected connection string in the config file. In such case the connection strings are not only added to the config file but a specific settings are registered in the Settings.settings XML file (and the corresponding code behind).

Kind regards,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Sam
Top achievements
Rank 2
answered on 08 Feb 2011, 11:59 PM
Hi Steve,

I am using your SQLDatasource Component to connect to database, but I want to control its connection programmatically.

When the report was first built yes the SQLDatasource kept the connection string the settings.xml file -> app.config file. But when my design was over, I wanted to erase any connection settings in the SQLDatasource which were done during design time, and control the connection at runtime.

So I deleted the connection string from the sql datasource, and then deleted the <ConnectionString> properties from the Settings.xml file and app.config file. So my app.config file has no connection string properties.

At runtime I issue the following in the rpt.vb file:
Public Sub New()
        InitializeComponent()
  
        Me.qByCompany.ConnectionString = "server=" & IMSCommon.SQLDBHandler.Server & ";User Id=MyUser;password=MyPWD;database=" & IMSCommon.SQLDBHandler.DBName & ";Persist Security Info=True"
        Me.qByCompany.ProviderName = "MySql.Data.MySqlClient"
  
 End Sub

So I had hoped that at runtime, the appropriate connectionString would be set. (qByCompany being the SQLDatasource which is attached to the Chart1.Datasource via design)

So as you see I do not want the SQLDatasource component to be dependent on any application settings.

The build runs OK on my dev PC, but when deployed I instantly get the connection error. It connects to the same database as the program login, so no issues there. What I was wondering is whether the report components uses any Temp directory where the user doesnt have rights to. Otherwise I am failing to understand why I am not being able to programmatically control the datasource connection.

"The update to the post which I had posted has been resolved" ..

I had to set the correct connectionString in the qByCompany and run it, so the preview could run correctly. But the first major error still remains.

Regards,
Sam

** Updated the Trace files of the 2 computers dev machine and client machine.
0
Steve
Telerik team
answered on 14 Feb 2011, 01:40 PM
Hi Sam,

The code you have used in the report constructor should work. In fact when you're in the Report and/or Data Source Wizards actually but do not instruct them to save the selected connection string, it would be saved in the report InitializeComponent method (short video attached) instead of the config file.
So you see having this same code moved from InitializeComponent to the report constructor is basically the same thing and there must be some other reason that this is not working on your end. Debug your application and verify that this connectionString does indeed work and is correct. You can make the same test as we did with the provided examples and compare the differences on your end.

Best wishes,
Steve
the Telerik team
Get started with Telerik Reporting with numerous videos and detailed documentation.
0
Sam
Top achievements
Rank 2
answered on 16 Feb 2011, 03:11 AM
Hi Steve,

Thanks for your help and the video. The videos and forums all talk of Telerik reports being used in web application whereby you just change the web.config file to point to the database.

My Scenario was different, I was doing a Forms Application and using MySQL as the database. My situation has now been solved, but I did spend a hell of a lot time trying to think why it wasn't working on the clients.

The installer for the Application installs all the necessary dll's on the client machine for the program to run. So I had assumed that nothing extra was required and the program ran perfectly minus the reporting. What was needed, was an installation of the MySQL .NET Connector on all the clients, although the dll itself was in the Program Files\MyApplication folder, registered by MyApplication installer.

This was strange, but it could be for the fact that the line in code ...

Me.qByCompany.ProviderName = "MySql.Data.MySqlClient" 

was failing to find any provider if the MySQL.NET connector was not installed on the client machines.

Thank you. God bless.
Tags
General Discussions
Asked by
Sam
Top achievements
Rank 2
Answers by
Sam
Top achievements
Rank 2
Steve
Telerik team
Share this question
or