Advertise with us

how i'm going to include connection file in

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. 
Last updated:6/12/2013 8:17:41 AM

1 Answers


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

Last updated:6/12/2013 8:17:41 AM