Click here to Skip to main content
13,457,199 members
Rate this:
Please Sign up or sign in to vote.
See more:
In my project there is a connection-string such that :

       <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" />

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 16-Feb-15 4:21am
Updated 16-Feb-15 4:27am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180322.1 | Last Updated 16 Feb 2015
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100