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:
what is the way to make entity framework sql server 2005 connectionstring dynamic? my entity framework connectionstring stored in app.config file. when i made a windows application and after making exe file, i want to install it any computer without changing connectionstring myself. the software will be automatically connected to the database. please help me. thanks in advance.

[EDIT]
From OP (accidentally posted as a Solution):

Here is my connectionstring.

<add name="ProductEntities" connectionstring="metadata=res://*/DBEntity.Model1.csdl|res://*/DBEntity.Model1.ssdl|res://*/DBEntity.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=DEV2-PC\SQLEXPRESS;Initial Catalog=D:\DEVELOPMENT\DBFILES\PRODUCT.MDF;Integrated Security=True;MultipleActiveResultSets=True&quot;" providername="System.Data.EntityClient" />
[/EDIT]
Posted
Updated 21-Mar-14 20:38pm
v3

Create a separate form in your application for server settings which will update your app.config file.

Use these are at top in your form coding. Change the name of "MMISCONFIG" to your connection string key.

VB
Imports System.IO
Imports System.Text
Imports System.Configuration
Imports Microsoft.Win32
Imports System


Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click


    Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
    If Me.rb_ipaddress.Checked = True Then
        config.AppSettings.Settings.Item(&quot;MMISCONFIG&quot;).Value = Me.txt_ipaddress.Text
    Else
        config.AppSettings.Settings.Item(&quot;MMISCONFIG&quot;).Value = Me.txt_server_name.Text
    End If

    config.Save(ConfigurationSaveMode.Modified)

    MsgBox(&quot;The Server Name/IP Address successfully Changed.&quot; &amp; vbCrLf &amp; &quot;For New Settings your application will restart automatically!&quot;, MsgBoxStyle.Information, &quot;Server Alert&quot;)
    Application.Restart()
End Sub</pre>
 
Share this answer
 
Comments
Suman Maji 21-Mar-14 8:09am    
this is for sqlclient connectionstring where user defined server name and ip address. but i want entity framework connectionstring.
sohail awr 21-Mar-14 9:52am    
First you tell your app.config connection string so that I will be able to understand what do you want.
Suman Maji 22-Mar-14 1:24am    
Here is my connectionstring.

<add name="ProductEntities" connectionstring="metadata=res://*/DBEntity.Model1.csdl|res://*/DBEntity.Model1.ssdl|res://*/DBEntity.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=DEV2-PC\SQLEXPRESS;Initial Catalog=D:\DEVELOPMENT\DBFILES\PRODUCT.MDF;Integrated Security=True;MultipleActiveResultSets=True"" providername="System.Data.EntityClient">
Here is my connectionstring.

<add name="ProductEntities" connectionstring="metadata=res://*/DBEntity.Model1.csdl|res://*/DBEntity.Model1.ssdl|res://*/DBEntity.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=DEV2-PC\SQLEXPRESS;Initial Catalog=D:\DEVELOPMENT\DBFILES\PRODUCT.MDF;Integrated Security=True;MultipleActiveResultSets=True"" providername="System.Data.EntityClient">
 
Share this answer
 
Comments
Suman Maji 22-Mar-14 1:35am    
Here is my connectionstring.

<!--<add name="ProductEntities" connectionstring="metadata=res://*/DBEntity.Model1.csdl|res://*/DBEntity.Model1.ssdl|res://*/DBEntity.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=DEV2-PC\SQLEXPRESS;Initial Catalog=D:\DEVELOPMENT\DBFILES\PRODUCT.MDF;Integrated Security=True;MultipleActiveResultSets=True"" providername="System.Data.EntityClient">-->

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