spocker Posted May 7, 2020 at 05:44 PM Report Share #618056 Posted May 7, 2020 at 05:44 PM 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 More sharing options...
M6 Posted May 8, 2020 at 03:16 PM Report Share #618064 Posted May 8, 2020 at 03:16 PM 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 More sharing options...
spocker Posted May 8, 2020 at 03:59 PM Author Report Share #618065 Posted May 8, 2020 at 03:59 PM 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 More sharing options...
M6 Posted May 9, 2020 at 09:46 AM Report Share #618066 Posted May 9, 2020 at 09:46 AM Vê a documentação: https://docs.microsoft.com/en-us/dotnet/api/system.configuration.configurationmanager?view=dotnet-plat-ext-3.1 https://docs.microsoft.com/en-us/dotnet/api/system.configuration.configurationmanager.appsettings?view=dotnet-plat-ext-3.1 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now