Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Updating ConnectionString of a Dataset at Run-Time
 

Updating ConnectionString of a Dataset at Run-Time

Hello all ADO/DataBinding Gurus.

I will start by mentionning that I'm fairly new to Databinding/.Net/C#.

I am currently developping a small management tool for our company to access a SQL database we are running.

I created different user account in the database having different previleges.

What I wanted to do, is to have a login form at the beginning of the management tool to allow the user to enter their own credentials. After that some read/write access teststo the different table would be perform and would help define the tables that the user would be able to have access (see).

The problem that I am having is related to the connection string. It is stored in the app.config (settings.settings) as a connectionstring under application type which makes it impossible to edit at runtime.

So I figured lets append the username/passform I retreive from the login form to the string right before creating the connection. The problem is that the following code is generated by the compiler so I can't edit it.

Code Snippet

[System.Diagnostics.DebuggerNonUserCodeAttribute()]

private void InitConnection()

{

this._connection = new System.Data.SqlClient.SqlConnection();

this._connection.ConnectionString = global::MY_Management_Tool.Properties.Settings.Default.MYConnectionString;

}

I have been searching for quite a while now and still haven't found a simple solution.

Am I trying to do something impossible ? Is my vision of thing just wrong ?

Any input would be greatly appreciated.

Regars,

Sly.

sboily  Thursday, April 10, 2008 4:02 AM

you can save it as a string in settings.settings

or you can try this

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=605773&SiteID=1

DinoMulahusic   Thursday, April 10, 2008 9:02 AM

you can save it as a string in settings.settings

or you can try this

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=605773&SiteID=1

DinoMulahusic   Thursday, April 10, 2008 9:02 AM

I tried changing the connection string to a string type which allows me to make it User-Mode.

Is there a dissavandtage of doing so vs using a real connectionString type variable ?

sboily  Thursday, April 10, 2008 7:58 PM

I don't know any disadvantages. maybe someone who has greater knowledge than i have Smile

DinoMulahusic   Friday, April 11, 2008 5:51 AM

You can use google to search for other answers

Custom Search

More Threads

• Cannot insert date in datagridview
• How to know the cell of the datagridview contains any data or not???
• icons in target datagridview
• DataGridView inside UserControl auto removing Friend WithEvents modifier
• TableAdapter and DataSet
• Getting data from fields in the "current" row ????
• Understanding Binding Syntax help
• How do I ask user for confirmation when deleting a record ?
• Performing search on dataset
• Set Primary Key for Untyped DataTable