473,770 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DatabaseConnect ion Strings

6 New Member
Can anyone explain how these work in relation to setting and application setting files. I know that application settings can not be modified programatically at runtime, although they can be changed in the XML.
(I did try adding a set method in my settings.cs to allow me to update the application scoped databaseconnect ion string, but VS was not being foole d by that). However, I want to change my DatabaseConnect ion string (to point at a different database), but the property is an application and not a user one.

My objective is simple I'd like the user to be able to open a different sdf (database file) from the one currently in use, and for that to then be saved for next time.
Jan 10 '09 #1
4 1333
Bassem
344 Contributor
Hi,
Why didn't hard-code the connection string for a SqlDataSource and modify it using a OpenFileDialog.
Jan 10 '09 #2
jonc1
6 New Member
Hi,
Thank you! I did think of that but VS created the connection for me and I assume pointed the DataSet to it. How would\where would I modify my existing connection ? I can't find the SqlServer connection object that VS MUST (I guess) have created?
.
Jan 10 '09 #3
Bassem
344 Contributor
No instead of drag and drop the SqlDataSource,
create a class that accept either the name of the database or the absolute location of the database, i did some thing like this before.
Expand|Select|Wrap|Line Numbers
  1. public class DataClass
  2. {
  3.     private SqlDataSource sqlDataSource;
  4.     public DataClass(string name)
  5.     {
  6.         sqlDataSource = new SqlDataSource();
  7.         sqlDataSource.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\" + name + ";Integrated Security=True;User Instance=True";
  8.     }
  9.  
  10.     public SqlDataSource SqlDataSource
  11.     {
  12.         get { return sqlDataSource; }
  13.     }
  14. }
  15.  
now you can pass the name of the database and re-bind your control

Note: you have to store your queries as stored procedures in each database, or you have to store a very long dictionary, and that makes no sense.

OK, i did it for .mdf database and i'm not familiar with db, and you're using .sdf db. I don't know if there will be a problem ??!
Jan 10 '09 #4
mldisibio
190 Recognized Expert New Member
Actually, you can modify your app.config file at runtime. You can also store multiple connection strings in the connectionStrin g section, or you can dynamically add new ones as the application is running.

To see an example of opening, modifying and saving the app.config file, see: ConfigurationMa nager.RefreshSe ction Method (System.Configu ration)

For an example of adding a new connectionStrin g to the configuration file, see:
ConnectionStrin gSettingsCollec tion.Add Method (System.Configu ration)
Jan 12 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

20
5777
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT" >>>c = extract(a,b) >>>print c "abcdefghijklmnop"
17
7400
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently interchangeable in all circumstances (as long as they're paired) so there's no overloading to muddy the language. Of course there could be some interesting problems with current code that doesn't make a distinction, but it would be dead easy to fix...
16
2435
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold any arbitrary data, even binary data such as photos and movies.They are of course also good for their traditional role of storing and manipulating text." This view of strings is about a decade out of date with modern programmimg practice. From...
4
10538
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three sets of character strings from the user. Then I want to run through each element and compare the two strings. If they match I print they match... I'm having a bit of trouble with the actual loop through each array using the pointers and comparing...
25
3572
by: Rainmaker | last post by:
Hi, Can anyone tell me an efficient algorithm to sort an array of strings? Keep in mind that this array is HUGE and so the algorithm should me efficient enough to deal with it. Thanks
6
1760
by: Broeisi | last post by:
Hello, I wrote the tiny progam below just to understand arrays and strings better. I have 2 questions about arrays and strings in C. 1. Why is it that when you want to assign a string to an character array that you must use the strcpy() function?
2
22608
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be read (the file will be written by only this program); file can be either in text or binary (preferably binary as the files may be read repeatedly); the amount and size of strings in the array won't be known until run time (in the example I have it in...
1
1946
by: esimons | last post by:
I am searching for days now to get a concrete example of how to use the __sleep() and __wakeup() function in a class to restore a databaseconnection when passing an object from one page to another by putting it in a session-variable. What I already know is that you should load the class before the session_start() function etc... What I DO NOT know is how the concrete code in the __sleep() and __wakeup() functions should be in order to...
95
5423
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ____________________________________ | | | ------------------ | | | BUTTON | | | ...
0
9617
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.