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

ORM Initialization Erorr (SQL Server)

3 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Steve
Top achievements
Rank 1
Steve asked on 09 Jul 2010, 04:10 PM
I am experiencing the following error when using Telerik ORM (2010.1 624)

System.ArgumentException: Format of the initialization string does not conform to specification starting at index 57.
   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.DBDriver.connect(ConnectionString connectionString, IDictionary driverProps)
   at OpenAccessRuntime.Relational.conn.RelationalConnectionPool.createRealCon()
   at OpenAccessRuntime.Relational.conn.RelationalConnectionPool.init()
   at OpenAccessRuntime.Relational.RelationalStorageManagerFactory.connect()
   at OpenAccessRuntime.Relational.RelationalStorageManagerFactory..ctor(StorageManagerFactoryBuilder b)
   at OpenAccessRuntime.storagemanager.StorageManagerFactoryBuilder.createSmfForURL()

I receive this error whenever it calls the IQueryable method for the database class. For instance:

public IQueryable<Certification> Certifications 
{
    get
    {
        return this.GetAll<Certification>();
    }
}

I have read a post in regards to a similar error with the ORM and SQL Azure, however the suggestions in that post have not worked.

Below is a portion of the code from EntityDiagram.cs

#pragma warning disable 1591 
//------------------------------------------------------------------------------ 
// <auto-generated> 
//     This code was generated by a tool. 
// 
//     Changes to this file may cause incorrect behavior and will be lost if 
//     the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 
using System; 
using System.Data; 
using System.Linq; 
using System.Linq.Expressions; 
using System.Data.Common; 
using System.Collections.Generic; 
using Telerik.OpenAccess; 
using NERCTest.Data; 
using Telerik.OpenAccess.Metadata; 
    
    
namespace NERCTest.Data  
{    
    public partial class NERC_CIP_Context : OpenAccessContext 
    
        private static string connectionStringName = "NERC_CIPConnection"
                
        private static BackendConfiguration backend = GetBackendConfiguration(); 
            
                
        private static MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource("NERCTestEntityDiagrams.rlinq"); 
        
        public NERC_CIP_Context() 
            :base(connectionStringName, backend, metadataSource) 
        { } 
            
        public NERC_CIP_Context(string connection) 
            :base(connection, backend, metadataSource) 
        { } 
        
        public NERC_CIP_Context(BackendConfiguration backendConfiguration) 
            :base(connectionStringName, backendConfiguration, metadataSource) 
        { } 
                
        public NERC_CIP_Context(string connection, MetadataSource metadataSource) 
            :base(connection, backend, metadataSource) 
        { } 
            
        public NERC_CIP_Context(string connection, BackendConfiguration backendConfiguration, MetadataSource metadataSource) 
            :base(connection, backendConfiguration, metadataSource) 
        { } 
                
        public IQueryable<Certification> Certifications  
        
            get
            
                return this.GetAll<Certification>(); 
            
        
            
        public IQueryable<Contact> Contacts 
        {
            get
            {
                return this.GetAll<Contact>();
            }
        }  
                  
        public static BackendConfiguration GetBackendConfiguration() 
        
            BackendConfiguration backend = new BackendConfiguration(); 
            backend.Backend = "mssql"
            return backend; 
        
    
#pragma warning restore 1591

Also here is a the code from the App.Config file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="NERC_CIPConnection" connectionString="data source=.;initial catalog=NERC_CIP;integrated security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

Here is the code from Default.aspx, which is what I am using to call the OpenAccessContext and query the database

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NERCTest.Data;
  
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
  
        using (NERC_CIP_Context context = new NERC_CIP_Context())
        {
            var query = from c in context.Contacts
                        where c.ContactId == 1
                        select c;
  
            foreach (var contact in query)
            {
                Console.WriteLine("ContactId: {0}, FirstName: {1}", contact.ContactId, contact.FirstName);
            }
        }
    }
}

This is extremely urgent as I am working on a tight project schedule and I would like to use the ORM. I have tested it with different projects, connecting to local database or one on the server, with a using statement or just creating the context. I have followed the examples to a tee and to no avail. Please help. Thank you!

3 Answers, 1 is accepted

Sort by
0
Accepted
Jeremy
Top achievements
Rank 1
answered on 12 Jul 2010, 03:19 PM
To resolve this error simply copy the connection string from the App.Config of the class library holding your domain model into the App.Config/Web.Config of the project running hosing your ORM code.  In my case, I am running the ORM code in an IIS hosted web service.  I had to copy the connection string from the App.Config of my Business Entities class library into the Web.Config of the web service host project.
0
Steve
Top achievements
Rank 1
answered on 12 Jul 2010, 04:31 PM
Jeremy,
   Thanks for the solution. That worked perfectly. Is there an instace in which the connectionString that is added to the class library is used or does it always defer to the app/web.config in the web project? If not, why is it created?

Thanks,
 -Steve-
0
Serge
Telerik team
answered on 14 Jul 2010, 09:47 AM
Hi Steve,

There is exactly one.config file used as the default configuration by the running application.
Inside a library project that contains Telerik OpenAccess ORM domain models we use an exclusively added App.config (no .config files are usually used in library projects) for the purposes of design-time. To ensure that the connection is resolved correctly during runtime, it is best to just copy the connection string to the .config file of the application project (at design-time we cannot analyze which one is the actual application project).

This is in fact standard approach when using ADO.NET connection strings and developing under .NET. I think this msdn article will be interesting for you.

Please contact us back if you need further assistance.

Sincerely yours,
Serge
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Steve
Top achievements
Rank 1
Answers by
Jeremy
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Serge
Telerik team
Share this question
or