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

Exception in design time missing connection string

5 Answers 349 Views
Design Time (Visual Designer & Tools)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcel
Top achievements
Rank 1
Marcel asked on 28 Jun 2013, 11:44 AM
Hello Forum

I bumped to a problem when evaluating TELERIK components.
I created OA ORM modell. All fine and works. I added a raddataform to a wpf window. When I set datacontext to the OA main class object (which I can choose in property dialog of the dataform from the references of my wpf project) I get following exception in place of the raddataform component (the same situation with radgridview) :

ConfigurationErrorsException: A connection string was referenced by name 'InvoicingConnectionULTIMATUS' but could not be resolved through the web.config or the executables app.config file.

Stack Trace:
 at Telerik.OpenAccess.RT.Adonet2Generic.Impl.DBDriver.connect(ConnectionString connectionString, IDictionary driverProps, ConnectionPoolType poolType, LogEventStore pes)
   at OpenAccessRuntime.Relational.sql.SqlDriver.InitializeFor(ConnectionString connectionString, Boolean noConnect, PropertySet props, DBDriver& driver, Connection& conn, ConnectionPoolType poolType)
   at OpenAccessRuntime.Relational.RelationalStorageManagerFactory..ctor(StorageManagerFactoryBuilder b)
   at OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createSmfForURL()

InnerException: None

I searched the web but none of the things apply to me as I have following situation:
- ORM Project is built and ready and works fine with the given connection strings in its app.config files
- WPF project is built and works
- WPF project's app.config contains copy-pasted part of the connection strings section from the ORM project
- Runtime runs fine (when I set datacontext and itemssource in code)

I tried also to copy the WPF's app.config under the <appname>.config but to no avail.

This is my app.config in WPF:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<connectionStrings>

<add name="InvoicingConnectionULTIMATUS" connectionString="data source=(localdb)\ULTIMATUS;initial catalog=Invoicing;integrated security=True" providerName="System.Data.SqlClient" />

</connectionStrings>

<startup>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

</startup>

</configuration>


This is my app.config in ORM:

<?xml version="1.0" encoding="utf-8"?>

<configuration>

<connectionStrings><add name="InvoicingConnectionULTIMATUS" connectionString="data source=(localdb)\ULTIMATUS;initial catalog=Invoicing;integrated security=True" providerName="System.Data.SqlClient" /></connectionStrings>

</configuration>



I basically don't like setting things somewhere in code when there's an option for it during design time.

Can you help me with this one?

5 Answers, 1 is accepted

Sort by
0
Dimitar Tachev
Telerik team
answered on 03 Jul 2013, 11:14 AM
Hi Marcel,

 
This error could be caused by the following reasons:

1) The connection string is missing in the app.config file of the WPF application.

2) There is a mismatch between the connection string name in the app.config and the one used by the OpenAccessContext.



For your convenience I also prepared a sample application demonstrating a sample integration of OpenAccess ORM and the RadDataForm - please find it attached.

You could also take a look at the WPF section of our Samples Kit where you could find end-to-end applications demonstrating the OpenAccess ORM integration with WPF.

I hope this helps. Do not hesitate to contact us back if you need any further assistance.

Regards,
Dimitar Tachev
Telerik
OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
0
Marcel
Top achievements
Rank 1
answered on 03 Jul 2013, 01:56 PM
Hello Dimitar   

Thank you for your response. But your suggestions don't solve the problem at all. As I wrote in my first post, I double checked all the "normal" possibilities for this error. None of them apply to me. I post you screenshot of the VS showing the error in the project you sent me. You can clearly see what I mean there.

VS 2012 Screenshot
0
Accepted
Dimitar Tachev
Telerik team
answered on 08 Jul 2013, 10:31 AM
Hello Marcel,

 
Thank you for the provided screenshot.

After reviewing the code in the MainWindow.xaml I found out that an OpenAccessContext instance is directly passed to the DataContext property of the RadDataForm.

Using this approach I was able to reproduce the problematic behavior locally and the reason for getting the error is that it is trying to create an instance of your OpenAccessContext in design time when it is still in the Visual Studio process where the connection string could not be found - the WPF application is not running yet.

Starting the application it should work properly because it will get the connection string from the app.config of the WPF application instead of the Visual Studio one.

In order to fix this issue I suggest you pass the DataContext or the ItemContext of the RadDataForm through a property of a ViewModel instead of directly in the XAML.

You could find detailed examples of our recommended approaches for using Telerik OpenAccess ORM with WPF in the sample applications of our Samples Kit that I mentioned in the first post.

I hope this helps. Do not hesitate to contact us back if you need any further assistance.

Regards,
Dimitar Tachev
Telerik
OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
0
Dennis
Top achievements
Rank 1
answered on 19 Dec 2013, 10:00 PM
Since the problem is the reference to the connection within the web.config, and it only happens when running from within Visual Studio as part of the temporary web server, you can change the connectionStringName string within the model class to the actual string.  when pushing to production and/or a regular web server just change it back.

public partial class EntitiesModel : OpenAccessContext, IEntitiesModelUnitOfWork
{
        private static string connectionStringName = @"MyConnection";

becomes

public partial class EntitiesModel : OpenAccessContext, IEntitiesModelUnitOfWork
{
        private static string connectionStringName = "data source=MyServer;initial catalog=MyDatabase;integrated security=True";//@"MyConnection";

just change the commented out portion and replace the string later

0
Kaloyan Nikolov
Telerik team
answered on 20 Dec 2013, 08:46 AM
Hello Dennis,

This approach will work, but I would not suggest it because any modifications in the generated context class will be replaced with the standard code when you alter you domain model. This approach could be used for code first scenarios with fluent mapping.

Nevertheless it should not be a problem to retrieve a connection string from the configuration file by its connection name for both the Development Web Server (Cassini) and IIS. 


Regards,
Kaloyan Nikolov
Telerik
OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
Tags
Design Time (Visual Designer & Tools)
Asked by
Marcel
Top achievements
Rank 1
Answers by
Dimitar Tachev
Telerik team
Marcel
Top achievements
Rank 1
Dennis
Top achievements
Rank 1
Kaloyan Nikolov
Telerik team
Share this question
or