Jump to content

appconfig


spocker

Recommended Posts

Boa tarde

como devo fazer para no appconfig preencher o connectionString com os dados recolhidos no userSettings ou seja

Data Source= <setting name="SqlSrv" serializeAs="String"> <value /> </setting>

por exemplo

<connectionStrings>
    <add name="conexao" connectionString="Data Source=; Initial Catalog=; User Id=; Password=;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
    <userSettings>
        <TD.Properties.Settings>
            <setting name="SqlSrv" serializeAs="String">
                <value />
            </setting>
            <setting name="User" serializeAs="String">
                <value />
            </setting>
            <setting name="Pass" serializeAs="String">
                <value />
            </setting>
            <setting name="BD" serializeAs="String">
                <value />
            </setting>
        </TD.Properties.Settings>
    </userSettings>
Link to comment
Share on other sites

Não sei se compreendi a duvida, mas da mesma forma que quando preenches os dados do userSettings, preenches os dados da connection string.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Boa tarde

eu pretendo preencher a informação da conectionString que esta no appconfig com os values que atribui aos user setting.

eu tenho uma class

namespace TD.Class.Conexao
{
    public class ConecSql
    {
        public static string StringConexao ()
        {
            var conn = "";
            try
            {
                conn = ConfigurationManager.ConnectionStrings[conexao].ToString();
            }
            catch (Exception)
            {

            }
            return conn;
        }
    }
}

e no appconfig

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="TD.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <connectionStrings>
    <add name="conexao" connectionString="Data Source=; Initial Catalog=; User Id=; Password=;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
    <userSettings>
        <TD.Properties.Settings>
            <setting name="SqlSrv" serializeAs="String">
                <value />
            </setting>
            <setting name="User" serializeAs="String">
                <value />
            </setting>
            <setting name="Pass" serializeAs="String">
                <value />
            </setting>
            <setting name="BD" serializeAs="String">
                <value />
            </setting>
        </TD.Properties.Settings>
    </userSettings>
</configuration>

e para preencher os user settings

private void bt_gravar_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.SqlSrv = txt_serv.Text;
            Properties.Settings.Default.User   = txt_utiliz.Text;
            Properties.Settings.Default.Pass   = txt_pass.Text;
            Properties.Settings.Default.BD     = txt_bd.Text;
            Properties.Settings.Default.Save();
        }

não estou a ver como posso alterar a string conexao no appconfig com os dados que enviei para o usersetting

Link to comment
Share on other sites

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.