473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Changing Connectionstring propertys RT?????

Scenario: i have a little programm that uses OleDb.connection to connect to
a database... the datasource is C:\programm Files\Database.mdb now i want to
change the datasource for the connection while i am reading the datasource
string from a file !!!! Cause the user want to put the database a place i
dont noe yet!!!(e.g a fileserver on the network!)

Code:
private void Form1_Load(object sender, System.EventArgs e)

{

string Serverpath;

try

{

// Create an instance of StreamReader to read from a file.

// The using statement also closes the StreamReader.

using(StreamReader sr = new StreamReader("Serverpath.txt"))

{

Serverpath = sr.ReadLine();

}
setpath(Serverpath);


}

catch(Exception b)

{
MessageBox.Show("File Could not be Read " + b);

}

label8.Text = Data_Connection.ConnectionString;

}

private void setpath(string str)

{

Data_Connection.DataSource = str; // variable from textfile (path)
}
C# says this while i am compiling

C:\Documents and Settings\f28403\My Documents\Visual Studio
Projects\WindowsApplication3\Form1.cs(722): Property or indexer
'System.Data.OleDb.OleDbConnection.DataSource' cannot be assigned to -- it
is read only

Is there anyone who can help me!!!


Nov 15 '05 #1
1 2785
SurfCoder,

What you should do is create a new instance of the OleDbConnection,
using the connection string that has the location of the new data. Then,
you can set Data_Connection to this new connection.

Generally speaking, I think it is a better idea to create a new
connection, open it, close it, and then release it, and not have one
connection lying around that you use for everything.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"SurfCoder" <Su************@yahoo.de> wrote in message
news:uG*************@TK2MSFTNGP10.phx.gbl...
Scenario: i have a little programm that uses OleDb.connection to connect to a database... the datasource is C:\programm Files\Database.mdb now i want to change the datasource for the connection while i am reading the datasource
string from a file !!!! Cause the user want to put the database a place i
dont noe yet!!!(e.g a fileserver on the network!)

Code:
private void Form1_Load(object sender, System.EventArgs e)

{

string Serverpath;

try

{

// Create an instance of StreamReader to read from a file.

// The using statement also closes the StreamReader.

using(StreamReader sr = new StreamReader("Serverpath.txt"))

{

Serverpath = sr.ReadLine();

}
setpath(Serverpath);


}

catch(Exception b)

{
MessageBox.Show("File Could not be Read " + b);

}

label8.Text = Data_Connection.ConnectionString;

}

private void setpath(string str)

{

Data_Connection.DataSource = str; // variable from textfile (path)
}
C# says this while i am compiling

C:\Documents and Settings\f28403\My Documents\Visual Studio
Projects\WindowsApplication3\Form1.cs(722): Property or indexer
'System.Data.OleDb.OleDbConnection.DataSource' cannot be assigned to -- it
is read only

Is there anyone who can help me!!!

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim Nelson | last post by:
I am building a data bound application for SQL server which all the forms I use sqlconnections generated by VS. I want to have a login form that changes the connection depending upon login...
5
by: Wolfgang | last post by:
Dear all, I've a lot of buttons named button1..button100 and want to change some of there propertys. Maintaining the overview I'm looking for a possibility for something like: ...
7
by: Dan Sikorsky | last post by:
How do you iterate thru a dataset to change money fields to a different value? Here's what I have. My dataset is filled directly from a stored procedure. ' Create Instance of Connection and...
0
by: Olivier Salzgeber | last post by:
Hello everybody I have an application which is grouped in a MainApplication and several Modules (DLL's) The Main Application is basically a Form with a NavigationBar on the Left Side (like in...
0
by: VB Programmer | last post by:
ASP.NET 2.0 site... Using web deployment project. Allowed web.config to be updateable. Settings not only in web.config but also in appSettings.config and connectionStrings.config. Question:...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
5
by: Kimmo Laine | last post by:
Hi is there a way to change propertys attribute from the code? Letīs say that i have the following property in my class: public int Count } Is there a way to change the displayname, from...
1
by: Corey B | last post by:
I have a page with a DetailsView control and a SQLDataSource control. The SQLDataSource control is connected to an Access database. Everything works fine. Now I want to change the back end...
1
Sl1ver
by: Sl1ver | last post by:
I got a App.Config file. Its got two connection strings and one appsetting I've used the following code to change it but it doesn't seem to update the settings. Configuration config =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.