Print Page | Close Window

sqlbulkcopy connection string

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4277
Printed Date: 07-Oct-2025 at 2:32pm


Topic: sqlbulkcopy connection string
Posted By: BigA25
Subject: sqlbulkcopy connection string
Date Posted: 16-Aug-2013 at 3:20pm
For doing an import on a large number of rows (excel file) I decided to use sqlbulkcopy to have good performance.
The problem is that this requires a direct link to the database through a connection string. 

Is there a way to get this connection string from ideablade anywhere?



Replies:
Posted By: smi-mark
Date Posted: 16-Aug-2013 at 5:10pm
You can access the application properties and populate an EntityConnectionStringBuilder and access the ConnectionString property or you can instantiate an EntityManager and use this useful extension method I wrote.



    public static class EntityManagerFns
    {
        public static string GetConnectionString(this EntityManager entityManager, string keyName)
        {
            var resolver = entityManager.DataSourceResolver.ProbedKeyResolver;
            var key = (ClientEdmKey)resolver.GetKey(keyName, string.Empty, true);
            return key.ConnectionString;
        }
    }


You can then call Manager.GetConnectionString("WhateverEntities");

We use CodeFirst exclusively now, so I can't remember if the connection string returned will be an EF string or the raw SQL string.



Print Page | Close Window