Home > DeveloperSection > Forums > how i'm going to include connection file in vb.net?
Manoj Bhatt
Manoj Bhatt

Total Post:153

Posted on    June-11-2013 4:18 AM

 VB.Net VB.Net 

 1 Reply(s)
 864  View(s)
Rate this:
Hi Expert,

I'm using vb.net 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. 


Total Post:604

Posted on    June-12-2013 8:17 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick