SQL Server From .Net: Connecting Visual Studio Community Edition to SQ

  • timwell

    SSCarpal Tunnel

    Points: 4961

    Comments posted to this topic are about the item SQL Server From .Net: Connecting Visual Studio Community Edition to SQ

  • gbritton1

    SSCertifiable

    Points: 6520

    instead of:
     conn.ConnectionString = "Data Source=.\\sqlexpress;Initial Catalog=tempdb;Integrated Security=True";

    this is an option:
     conn.ConnectionString = @"Data Source=.\sqlexpress;Initial Catalog=tempdb;Integrated Security=True";

    or even:
    conn.ConnectionString = new SqlConnectionStringBuilder 
        {DataSource = @".\sqlexpress", InitialCatalog = "tempdb", IntegratedSecurity = true}.ToString();

    I'm using the builder more these days since you get compiler help and can't misspell keywords (though you still can mess up the arguments of course).

  • timwell

    SSCarpal Tunnel

    Points: 4961

    gbritton1 - Tuesday, May 8, 2018 11:53 AM

    instead of:
     conn.ConnectionString = "Data Source=.\\sqlexpress;Initial Catalog=tempdb;Integrated Security=True";

    this is an option:
     conn.ConnectionString = @"Data Source=.\sqlexpress;Initial Catalog=tempdb;Integrated Security=True";

    or even:
    conn.ConnectionString = new SqlConnectionStringBuilder 
        {DataSource = @".\sqlexpress", InitialCatalog = "tempdb", IntegratedSecurity = true}.ToString();

    I'm using the builder more these days since you get compiler help and can't misspell keywords (though you still can mess up the arguments of course).

    Yes, thanks for mentioning those options.  
    I first learned about the string builder when I was doing the research for the article on the connection string in this "occasional series" of articles.
    Maybe I should have said something like "... and any other way you can put a string together..."

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply