Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project there is a connection-string such that :

<connectionstrings>
       <add name="Employee_Management_System.My.MySettings.EMSDBConnectionString">
           connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\EMSDB.mdf;Integrated Security=True"

           providerName="System.Data.SqlClient" />
   </add></connectionstrings>

And when I see the properties of my database in server explorer the connection string is such that :

Data Source=(LocalDB)\v11.0;AttachDbFilename="F:\Employee Management System\Employee Management System\EMSDB.mdf";Integrated Security=True

But I want to set connection string like the above which is I app.config file
(i.e, the connection string string should be such that it should automatically determine the path)

And also when I try to set the connection-string which is in app.config file I could not access it.So how to do it.
Posted
Updated 16-Feb-15 4:27am
v3

1 solution

First add reference : System.Configuration
then in your code :

Imports System.Configuration



dim con as SqlConnection


in Load Event or whichever event you want write:
-----------------------------------------------------
con = New SqlConnection(ConfigurationManager.ConnectionStrings("Constr").ConnectionString)
-------------------------------------------------------

the name "Cnstr" is the name of connectionString which is in app.config file
 
Share this answer
 
Comments
Kuthuparakkal 16-Feb-15 11:12am    
Self goal.
A94 16-Feb-15 11:43am    
In above connection string the operation of insert,search etc works fine. But when I run application on different pc it gives error. So how to setup correct path. Any Idea

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