Cannot connect to database programatically

5 posts, 0 answers
  1. Kelly
    Kelly avatar
    7 posts
    Member since:
    Sep 2016

    Posted 21 Sep Link to this post

    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!!

  2. Kelly
    Kelly avatar
    7 posts
    Member since:
    Sep 2016

    Posted 21 Sep in reply to Kelly Link to this post

    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;

  3. DevCraft banner
  4. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 22 Sep Link to this post

    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
  5. Kelly
    Kelly avatar
    7 posts
    Member since:
    Sep 2016

    Posted 22 Sep in reply to Peter Link to this post

    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.

  6. Katia
    Admin
    Katia avatar
    309 posts

    Posted 27 Sep Link to this post

    Hello Kelly,

    Open the properties of SqlDataSource component and check if it has ProviderName set to System.Data.OleDb.
    You can 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
Back to Top
DevCraft banner