问题描述
什么是使实体框架sql server 2005 connectionstring动态化的方法?我的实体框架连接字符串存储在app.config文件中。当我制作一个Windows应用程序和制作exe文件后,我想安装它任何计算机,而不是自己更改连接字符串。该软件将自动连接到数据库。请帮我。提前谢谢。
从OP(意外发布为解决方案):
这是我的连接字符串。
< add name =ProductEntitiesconnectionstring =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;初始目录= D:\DEVELOPMENT \ DBFILES \PRODUCT.MDF; Integrated Security = True; MultipleActiveResultSets = True& quot; providername =System.Data.EntityClient/>
[/ EDIT]
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.
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="Data Source=DEV2-PC\SQLEXPRESS;Initial Catalog=D:\DEVELOPMENT\DBFILES\PRODUCT.MDF;Integrated Security=True;MultipleActiveResultSets=True"" providername="System.Data.EntityClient" />
[/EDIT]
推荐答案
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("MMISCONFIG").Value = Me.txt_ipaddress.Text
Else
config.AppSettings.Settings.Item("MMISCONFIG").Value = Me.txt_server_name.Text
End If
config.Save(ConfigurationSaveMode.Modified)
MsgBox("The Server Name/IP Address successfully Changed." & vbCrLf & "For New Settings your application will restart automatically!", MsgBoxStyle.Information, "Server Alert")
Application.Restart()
End Sub</pre>
这篇关于如何在Windows应用程序中生成动态实体框架Sql Server2005 Connectionstring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!