Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem with connectionstrings

Problem with connectionstrings

Scheduled Pinned Locked Moved Visual Basic
csharpvisual-studiosecurityhelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    desanti
    wrote on last edited by
    #1

    Hello ! I'm using visual studio 2013. In my app.config , there are 3 connections strings :

    <connectionStrings><add name="db1Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
    <add name="db2Entities" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
    <add name="db3Entities" connectionString="metadata=res://*/Model3.csdl|res://*/Model3.ssdl|res://*/Model3.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db3;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
    </connectionStrings>

    Now , I want to access these connections strings , using the following code :

    Dim connstringtemplate1 As String = System.Configuration.ConfigurationManager.ConnectionStrings(1).ConnectionString.ToString

    This string has "NULL" value

    Dim connstringtemplate2 As String = System.Configuration.ConfigurationManager.ConnectionStrings(2).ConnectionString.ToString

    This string has the first connection string

    Dim connstringtemplate3 As String = System.Configuration.ConfigurationManager.ConnectionStrings(3).ConnectionString.ToString

    This string has the second connection string

    Dim connstringtemplate4 As String = System.Configuration.ConfigurationManager.ConnectionStrings(4).ConnectionString.ToString

    This string has the third connection string Also if I use this :

    Dim nr As Integer = System.Configuration.ConfigurationManager.ConnectionStrings.Count

    The value of nr is 5. I have only 3 connection strings , so why there are 5 and the first is empty ? This problem appear after I have installed the Update 5 on visual studio 2013

    M Z 2 Replies Last reply
    0
    • D desanti

      Hello ! I'm using visual studio 2013. In my app.config , there are 3 connections strings :

      <connectionStrings><add name="db1Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
      <add name="db2Entities" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
      <add name="db3Entities" connectionString="metadata=res://*/Model3.csdl|res://*/Model3.ssdl|res://*/Model3.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db3;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
      </connectionStrings>

      Now , I want to access these connections strings , using the following code :

      Dim connstringtemplate1 As String = System.Configuration.ConfigurationManager.ConnectionStrings(1).ConnectionString.ToString

      This string has "NULL" value

      Dim connstringtemplate2 As String = System.Configuration.ConfigurationManager.ConnectionStrings(2).ConnectionString.ToString

      This string has the first connection string

      Dim connstringtemplate3 As String = System.Configuration.ConfigurationManager.ConnectionStrings(3).ConnectionString.ToString

      This string has the second connection string

      Dim connstringtemplate4 As String = System.Configuration.ConfigurationManager.ConnectionStrings(4).ConnectionString.ToString

      This string has the third connection string Also if I use this :

      Dim nr As Integer = System.Configuration.ConfigurationManager.ConnectionStrings.Count

      The value of nr is 5. I have only 3 connection strings , so why there are 5 and the first is empty ? This problem appear after I have installed the Update 5 on visual studio 2013

      M Offline
      M Offline
      Mathi Mani
      wrote on last edited by
      #2

      Why are you getting connectionstring by index instead of getting them by using their name?

      1 Reply Last reply
      0
      • D desanti

        Hello ! I'm using visual studio 2013. In my app.config , there are 3 connections strings :

        <connectionStrings><add name="db1Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
        <add name="db2Entities" connectionString="metadata=res://*/Model2.csdl|res://*/Model2.ssdl|res://*/Model2.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
        <add name="db3Entities" connectionString="metadata=res://*/Model3.csdl|res://*/Model3.ssdl|res://*/Model3.msl;provider=System.Data.SqlClient;provider connection string="data source=PERSONALPC\MSSQL2008R2;initial catalog=db3;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
        </connectionStrings>

        Now , I want to access these connections strings , using the following code :

        Dim connstringtemplate1 As String = System.Configuration.ConfigurationManager.ConnectionStrings(1).ConnectionString.ToString

        This string has "NULL" value

        Dim connstringtemplate2 As String = System.Configuration.ConfigurationManager.ConnectionStrings(2).ConnectionString.ToString

        This string has the first connection string

        Dim connstringtemplate3 As String = System.Configuration.ConfigurationManager.ConnectionStrings(3).ConnectionString.ToString

        This string has the second connection string

        Dim connstringtemplate4 As String = System.Configuration.ConfigurationManager.ConnectionStrings(4).ConnectionString.ToString

        This string has the third connection string Also if I use this :

        Dim nr As Integer = System.Configuration.ConfigurationManager.ConnectionStrings.Count

        The value of nr is 5. I have only 3 connection strings , so why there are 5 and the first is empty ? This problem appear after I have installed the Update 5 on visual studio 2013

        Z Offline
        Z Offline
        ZurdoDev
        wrote on last edited by
        #3

        desanti wrote:

        I have only 3 connection strings , so why there are 5 and the first is empty ?

        They are probably getting merged in from the machine.config file. You can use

        in .config to get rid of them. c# - ConfigurationManager.ConnectionStrings returns extra connection string from machine.config - Stack Overflow[^] But, as pointed out in the other response, the better option is to refer to them using a name rather than depending on their order.

        ConfigurationManager.ConnectionStrings[connectionName].ConnectionString

        There are only 10 types of people in the world, those who understand binary and those who don't.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups