1
I would like to mount using saved String: InstanciaSQLServer
, UserSQL
and PWSQL
, it is possible that?
Example of my app.config
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<-section name="BancoDeHoras.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<userSettings>
<BancoDeHoras.Properties.Settings>
<setting name="InstanciaSQLServer" serializeAs="String">
<value />
</setting>
<setting name="UserSQL" serializeAs="String">
<value />
</setting>
<setting name="PWSQL" serializeAs="String">
<value />
</setting>
</BancoDeHoras.Properties.Settings>
</userSettings>
<connectionStrings>
<add
name="conection"
connectionString ="Data Source =[InstanciaSQLServer]; Initial Catalog = BancoDeHoras; User id = [UserSQL]; pwd=[PWSQL]"/>
</connectionStrings>
Friend, welcome to the community, I suggest, read our FAQ, how to ask a question: https://answall.com/help/how-to-ask , because your question is not clear, and so it is difficult to help
– Thomas Erich Pimentel
@Ronivaldoroner: As complement: The Connection Strings Reference - https://www.connectionstrings.com/
– José Diz
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e5ae2b18-0795-49e8-a274-c3d52eccb8b3/connection-string-in-a-wpf-application?forum=wpf
– Aline
What I would like to do is use the values saved in the strings to mount the connection string. Example: string connection_BD = Data Source = [Instantiatsqlserver; Initial Catalog = Bancodehours; User id = [Usersql]; pwd=[PWSQL];
– Ronivaldo Roner
I fixed the example code, which is the correct way to write this connectionString?
– Ronivaldo Roner
I solved the problem in another way. I did not create the Connection String in the XML app.Config, I created it directly in the class responsible for making the connection. Thus my string was as follows: private Static string conexao_DB = $@"Data Source = {Properties.settings.Default.Instantiatsqlserver}; Initial Catalog = Bancodehoras; User id = {Properties.settings.Default.Usersql}; pwd={Properties.settings.Default.PWSQL}"; ---- I don’t know if this is the right way to go, but it’s the only one I’ve managed so far.
– Ronivaldo Roner
Is using
EntityFramework
?– Randrade