如何在Windows应用程序中生成动态实体框架Sql Server2005 Connectionstring? [英] How Will I Generate A Dynamic Entity Framework Sql Server2005 Connectionstring In Windows Application?

查看:85
本文介绍了如何在Windows应用程序中生成动态实体框架Sql Server2005 Connectionstring?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是使实体框架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=&quot;Data Source=DEV2-PC\SQLEXPRESS;Initial Catalog=D:\DEVELOPMENT\DBFILES\PRODUCT.MDF;Integrated Security=True;MultipleActiveResultSets=True&quot;" providername="System.Data.EntityClient" />
[/EDIT]

推荐答案

在服务器的应用程序中创建单独的表单将更新app.config文件的设置。



使用这些设置在表单编码的顶部。将MMISCONFIG的名称更改为您的连接字符串键。



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.

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>


这是我的连接字符串。



< add name =ProductEntitiesconnectionstring =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 = Trueprovidername =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">


这篇关于如何在Windows应用程序中生成动态实体框架Sql Server2005 Connectionstring?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆