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

Cannot connect to database programatically

4 Answers 421 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kelly
Top achievements
Rank 1
Kelly asked on 21 Sep 2016, 09:23 PM

Hello,

I'm having some issue connecting to a database. I'm using a Microsoft Access db and the standalone report designer. However, it is a requirement that I overwrite the data source's database connection programatically so that it is always using my WPF application's database ConnectionString in the app.config.  Using the standalone report designer is required because the client will be creating new reports and then previewing them, but ultimately dropping the report files on many machines which may have different db paths.

What DOES work is if embed my db connection in the report designer wizard - then the report will successfully show up in my application. However, this doesn't solve my issue of needing to use the app.config connection string.

My connection string looks like so:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyDatabase.mdb;

My code to change the datasource:
 

<p>var reportSource = new UriReportSource();<br>            reportSource.Uri = @"Reports/MyReport.trdp";</p><p>//Uses reportPackager.Unpackage<br>            var reportInstance = UnpackageReport(@"Reports/MyReport.trdp");<br>            var dataSource = new SqlDataSource();            <br>            dataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;<br>            dataSource.ProviderName = "Microsoft.Jet.OLEDB.4.0";<br>            reportInstance.DataSource = dataSource;<br>// Creates an InstanceReportSource<br>            var instanceReportSource = CreateInstanceReportSource(reportInstance, reportSource);<br>            this.ReportViewer1.ReportSource = instanceReportSource;      </p>

 

I get the error "Unable to find the required .Net Framework provider. It may not be installed."

How can this be true if I can otherwise access the same database using that connection string elsewhere in the application? And the embedded connection string will work correctly?

I'm hitting a wall here. I have seen other threads mention downloading the newest JET service pack but even Microsoft's support site says I should already have it (https://support.microsoft.com/en-us/kb/239114). I am on a 64 bit Windows 8 machine, and have my solution compiling to a 32 bit application.

Any help would be appreciated. Thank you!!

4 Answers, 1 is accepted

Sort by
0
Kelly
Top achievements
Rank 1
answered on 21 Sep 2016, 09:24 PM

Sorry for the formatting, here is my code (I guess I can't edit?)

var reportSource = new UriReportSource();

reportSource.Uri = @"Reports/MyReport.trdp";

//Uses reportPackager.Unpackage

var reportInstance = UnpackageReport(@"Reports/MyReport.trdp");

var dataSource = new SqlDataSource()

dataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;<br>            dataSource.ProviderName = "Microsoft.Jet.OLEDB.4.0";

reportInstance.DataSource = dataSource;

// Creates an InstanceReportSource

var instanceReportSource = CreateInstanceReportSource(reportInstance, reportSource);

this.ReportViewer1.ReportSource = instanceReportSource;

0
Peter
Telerik team
answered on 22 Sep 2016, 10:04 AM
Hello Kelly,

If you set up your connection strings as Shared in the SqlDataSource Wizard than a named connection string will be used. Telerik Reporting can resolve and work with named connection strings provided in the application configuration file (web.config or app.config). Thus adding the required connection string with the same name in the application configuration file should be enough for most of the scenarios. Still if for some reason you can not add the connection string in the configuration file and you have to provide the connection strings in runtime you can use the SetConnectionString() method from this article.

Regards,
Peter
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kelly
Top achievements
Rank 1
answered on 22 Sep 2016, 02:44 PM

Thanks Peter -

I've tried what you said before and just gave it another shot.  I set the sqlDataSources in my sample report to use a shared connection string that was named the same as my WPF application's app.config connection string.  Now I get the error "Keyword not supported: 'provider'".  When I use the SetConnectionString() code provided in the article I get the same error. Do you have any ideas? I am not sure what I am missing.

0
Katia
Telerik team
answered on 27 Sep 2016, 09:14 AM
Hello Kelly,

Open the properties of SqlDataSource component and check if it has ProviderName set to System.Data.OleDb.
You  also find an example of a connection string to an MDB file via Microsoft.Jet.OLEDB.4.0 in www.connectionstrings.com.

If the issue persists, please send us the report's definition (code) and the start project's config file in a support ticket so we can check the settings and provide you further suggestions.


Regards,
Katia
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Kelly
Top achievements
Rank 1
Answers by
Kelly
Top achievements
Rank 1
Peter
Telerik team
Katia
Telerik team
Share this question
or