i need help with passing parameters in the connectionString  
Author Message
guyndjeng





PostPosted: .NET Framework Data Access and Storage, i need help with passing parameters in the connectionString Top

i'm wanting to pass the values of 2 textboxes in a form in the connectionstring as uid and pwd. i've already created a new Login in SQL Server but when i'm passing the textBox1.text and the textBox2.text with the & concatenate operator the compiler yells at me

this is the code in my app.Config file where i stored the connectionstring

< xml version="1.0" encoding="utf-8" >

<configuration>

<appSettings>

<add key ="connectionString" value="Address=valid ip addess;Trusted_Connection = true; Database=Northwind; uid=" & textBox1.Text & "; pwd=" & textBox2.Text & " " />

</appSettings>

</configuration>

An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll

Additional information: The '&' character, hexadecimal value 0x26, cannot begin with a name. Line 4, position 115.

i desired each user of this application to authenticate against SQL Server and be granted access to their schema

please i need help

thanks



.NET Development32  
 
 
Luis D. Rojas





PostPosted: .NET Framework Data Access and Storage, i need help with passing parameters in the connectionString Top

Hi,

You can not have a TextBox instance value inside a connection string in a configuration file. You have to add pair values to pick up data from there, and in case you need to ask for some of those values to the user, you have to create the connection string based on those values

For storing and retrieving connection strings from config files check out this link

 And for building connection strings use the ConnectionStringBuilder. Check that info in this link too.

Best Regards



 
 
guyndjeng





PostPosted: .NET Framework Data Access and Storage, i need help with passing parameters in the connectionString Top

Thank you very muc Luis for your insight i'll start looking on that rightaway..

best regards...