New Posts New Posts RSS Feed: sqlbulkcopy connection string
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

sqlbulkcopy connection string

 Post Reply Post Reply
Author
BigA25 View Drop Down
Newbie
Newbie


Joined: 16-Aug-2013
Posts: 3
Post Options Post Options   Quote BigA25 Quote  Post ReplyReply Direct Link To This Post Topic: sqlbulkcopy connection string
    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?
Back to Top
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down