Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello!
I saw this code snippet on how to access the connection string from the app.config
Db.ConnectionString = ConfigurationManager.ConnectionStrings["con"].ToString();

my problem is it does not work for VB.Net... can anyone help me?
Posted
Comments
Ron Beyer 8-Jan-14 0:42am    
Did you add a reference to the System.Configuration.dll file? If you do, ConfigurationManager becomes available and you should be able to get your connection string provided you have it set up in the App.config file.
SkinnyGlass 8-Jan-14 0:46am    
my bad! I did not add the reference, now it's working. thanks :D

Hi
Maybe you did not using System.Configuration namespace :

XML
 <configuration>
  <connectionstrings>
    <add name="DBConnectionString">
      connectionString="Data Source=Manoj;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=admin123"
      providerName="System.Data.SqlClient" />
  </add></connectionstrings>
</configuration>


C#
using System.Configuration;

string nwConn = System.Configuration.ConfigurationManager.ConnectionStrings[1].ToString();


However you have many different solutions for reading connection string from app.config for example follow of these links:
Connection string App.Config
Connection Strings and Configuration Files
connection string and app config

Best Regards.
 
Share this answer
 
VB
Dim dbconn As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("con"))


HTML
<configuration>
  <appsettings>
    <add key="con" value="put your connection string here" />
  </appsettings></configuration>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900