473,611 Members | 2,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

change connection string dynamically

Hi,
At startup the user log on and chooses the name of a client from a
dropdownlist, which then changes dynamically the connection string (the
name of the client indicates which database to use).
I then change dynamically the connection string by doing :
My.Settings.Ite m("ConnectionSt ring") = "some connection sring"

The problem is that if another user loggs in and chooses another
client, then obviously it changes the connection string again and the
first user will be in trouble !

How can I change the connection string PER user ? In the setting file,
the connection string can only be an application-level variable and
can't be a user variable for some reason :(

Thank you

Jul 17 '06 #1
37 8935
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** ************@i4 2g2000cwa.googl egroups.com...
How can I change the connection string PER user ? In the setting file,
the connection string can only be an application-level variable and
can't be a user variable for some reason :(
What do you mean by the "setting" file? Do you mean web.config...?
Jul 17 '06 #2
Hi Mark,
No, by setting file I mean the Settings.settin gs file, which actually
interacts with the app.config file...
Any clue ?
Mark Rae wrote:
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** ************@i4 2g2000cwa.googl egroups.com...
How can I change the connection string PER user ? In the setting file,
the connection string can only be an application-level variable and
can't be a user variable for some reason :(

What do you mean by the "setting" file? Do you mean web.config...?
Jul 17 '06 #3
It looks like you're writing a Windows Forms App.

If so, you should post your question to the newsgroup:

microsoft.publi c.dotnet.framew ork

....on this same server.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
Hi Mark,
No, by setting file I mean the Settings.settin gs file, which actually
interacts with the app.config file...
Any clue ?
Mark Rae wrote:
>"sam44" <sa************ *@googlemail.co mwrote in message
news:11******* *************@i 42g2000cwa.goog legroups.com...
How can I change the connection string PER user ? In the setting file,
the connection string can only be an application-level variable and
can't be a user variable for some reason :(

What do you mean by the "setting" file? Do you mean web.config...?

Jul 17 '06 #4
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
No, by setting file I mean the Settings.settin gs file, which actually
interacts with the app.config file...
Ah...
Any clue ?
Yes - you're in the wrong newsgroup. This group is for ASP.NET.
Jul 17 '06 #5
No I'm not in the wrong group! I'm doing ASP.net !
My website has a business object, which is a vb.net project in visual
studio, that's why I also have a app.config file. So can someone help ?

Mark Rae wrote:
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
No, by setting file I mean the Settings.settin gs file, which actually
interacts with the app.config file...

Ah...
Any clue ?

Yes - you're in the wrong newsgroup. This group is for ASP.NET.
Jul 18 '06 #6
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
No I'm not in the wrong group! I'm doing ASP.net !
My website has a business object, which is a vb.net project in visual
studio, that's why I also have a app.config file. So can someone help ?
You know, if you'd said that in the first place... :-)

1) Store your "base" connection string in your business object's app.config
file (or anywhere else you like)

2) In your web app's Session_Start event, read in the base connection
string, amend it as necessary, and store the amended string as a Session
variable.

3) Amend your business object to allow the connection string to be passed to
it.

4) When referencing your business object, pass in the amended connection
string from the Session variable.
Jul 18 '06 #7
Thanks for your help Mark,
Yeah I should have been more explicit in my first post, sorry.

Regarding your solution, I'm not sure if I can do that in the
Session_Start event. When is this called ?
I need to amend my base connection string, once the user has correctely
logged in (ie, username + password are correct and he chose a valid
client in the list). The the identification stored procedure returns
the new connection string, which is the one I should use.
Is the Session_Start event going to be called each time I create a new
session variable?

Sam

Mark Rae wrote:
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
No I'm not in the wrong group! I'm doing ASP.net !
My website has a business object, which is a vb.net project in visual
studio, that's why I also have a app.config file. So can someone help ?

You know, if you'd said that in the first place... :-)

1) Store your "base" connection string in your business object's app.config
file (or anywhere else you like)

2) In your web app's Session_Start event, read in the base connection
string, amend it as necessary, and store the amended string as a Session
variable.

3) Amend your business object to allow the connection string to be passed to
it.

4) When referencing your business object, pass in the amended connection
string from the Session variable.
Jul 18 '06 #8
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Thanks for your help Mark,
Yeah I should have been more explicit in my first post, sorry.
S'OK...
Regarding your solution, I'm not sure if I can do that in the
Session_Start event. When is this called ?
The clue is in the name - the Session_Start event fires every time a session
starts i.e. every time a browser makes a new connection to your site.
I need to amend my base connection string, once the user has correctely
logged in (ie, username + password are correct and he chose a valid
client in the list). The the identification stored procedure returns
the new connection string, which is the one I should use.
Exactly.
Is the Session_Start event going to be called each time I create a new
session variable?
No - see above.
Jul 18 '06 #9
The clue is in the name - the Session_Start event fires every time a session
starts i.e. every time a browser makes a new connection to your site.
Ok, then it's too early in the process :) If Session_Start is fired
when the URL is requested, then obviously the user hasn't logged on
yet. Therefore I don't know anything about the new connection string at
that time and I can't amend the original one in this event. Does this
make sense ?

Sam

Mark Rae wrote:
"sam44" <sa************ *@googlemail.co mwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Thanks for your help Mark,
Yeah I should have been more explicit in my first post, sorry.

S'OK...
Regarding your solution, I'm not sure if I can do that in the
Session_Start event. When is this called ?

The clue is in the name - the Session_Start event fires every time a session
starts i.e. every time a browser makes a new connection to your site.
I need to amend my base connection string, once the user has correctely
logged in (ie, username + password are correct and he chose a valid
client in the list). The the identification stored procedure returns
the new connection string, which is the one I should use.

Exactly.
Is the Session_Start event going to be called each time I create a new
session variable?

No - see above.
Jul 18 '06 #10

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

Similar topics

3
1171
by: JJ | last post by:
Hello, I was wondering what the best way would be to dynamically determine and store connection string information. What I mean by this is that I want the application to user the servervariable to determine what location it is running in and then dynamically assign a connection string value based on that location. I was planning on doing this from the codebehind pages which works fine because I am able to use the response object to...
1
2851
by: stewart | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the caching section. So, in my code I add an item to the cache with an sqlCacheDependency, referencing the named sqlCacheDependency in the web.config and the database table it is to be based on (have enabled notificiations for that table). Fine. ...
7
11239
by: Henry | last post by:
I am writing a Windows forms VB.Net/MS SQL application via VS 2003 that utilizes Crystal Reports. I want to be able to dynamically set the report data source at run time. I'm trying to change the the reports "integrated security" from TRUE to FALSE via the "Set Location" dialog in the report designer with no success. It is not intuitive (at least not to me.) I get the following error:
3
3960
by: steph | last post by:
Hi, I've got below function to dynamically define and run pass-through queries. This works OK. But I don't want to have the connection string hard-coded, instead I want to reuse the existing connection. How can I achieve this? Thanks, Stephan
1
6050
by: Sankalp | last post by:
Hi, I am using VB 2005. My application has many data bound controls. The connection is stored in the app.config file. I want the application to start with a default connection string and while during the runtime, the user can click on a button and change the connection string without exiting the application. I would really appreciate any sort of help.
7
2507
by: harry | last post by:
I've set my database connection as an Application.Setting using the designer. Since Application.Settings are read only, how do I change the connection properties when deploying to another machine ? Thanks Harry
5
17768
by: ronlahav | last post by:
Dear all i Wonder how can i edit a node property (in C# not by hand :) ) i have the follwing XMl file (hibernate.cfg.xml) <?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" > <session-factory name="NHibernate.Test"> <!-- properties -->
2
6646
by: Hetal | last post by:
Hi... I am a newbie VB.NET developer and i am looking at working with ADO.NET rather than ADO. In one of our native VB application with ADO, we used to create 1 connection object and that would help us to connect to MS-SQL and MySQL alternatively based on the database type and connection string i provide. So, one connection object was good enough to connect to any of these 2 type of databases. The sample connection string we use to...
7
10104
OuTCasT
by: OuTCasT | last post by:
I know how to change the database and sqlserver for a crystal report Dim report As New ReportDocument Dim connection As IConnectionInfo Dim oldServerName As String = ".\SQLEXPRESS" Dim oldDatabaseName As String = oldDatabaseName Dim newServerName As String = newServerName Dim newDatabaseName As String = newDatabaseName Dim UserID As String = "" Dim Password As String = ""
0
8149
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
8097
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
8596
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8561
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...
0
8411
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7038
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5527
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4042
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
1411
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.