how i'm going to include connection file in

Total Post:154


 1719  View(s)
Rate this:
Hi Expert,

I'm using and oracle. this is my code connection with db

I want to establish connection string in VB.NET with Oracle database as following   

Dim connectionString As String = "Data Source = abc; User ID = abc; Password = abc;"
Dim sqlConnection As OracleClient.OracleConnection = New OracleClient.OracleConnection(connectionString)

It's work fine, but when I put connection string into apps.config, that's not working. My line of code as following

<add key="abc_connection" value="server=xyz;User ID=abc;Password=abc;database=abc;Connection Timeout=0"/>

what line of code I should use for replacing my code connection above ? so that i can call the apps.config file instead of using the code connection repeatedly.

Thanks in advance. 
  1. Re: how i'm going to include connection file in

    Hi Manoj,

    You can create a class with settings and add a property

    web config
    <add name="connectionstring" connectionString="server=xyz;UserID=abc;Password=abc;database=abc;Connection Timeout=0" />

    cs code

        public static string connStr
        { get { return ConfigurationManager.ConnectionStrings["abc_connection"].ConnectionString; } }
    if you want to use key in appconfig
     public static string abc_connection
        { get {return  ConfigurationManager.AppSettings["abc_connection"].ToString(); } }
    in vb

      Public Shared Function connStr() As String
        Return ConfigurationManager.ConnectionStrings("abc_connection").ConnectionString ''
    End Function
    Public Shared Function abc_connection() As String
        Return ConfigurationManager.AppSettings("abc_connection") ''
    End Function

      Modified On Mar-30-2018 03:26:15 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.