473,796 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to let user select a database connection?

Hello:

I'm using VS2005 with an ODBC database.

I am trying to add a Dialog to an existing Database application to allow the
user to select the database. We have 2 different databases with the same
schema so this is a very desirable function.

I can configure 2 different connection strings in app,config but I can't
figure out how to allow the user to select one or the other.

This should be a simple task but I seem to be missing something. I am very
new to VS2005 so please forgive me for being naïve.

Thanks

Edwin

Oct 26 '07 #1
5 5808
<connectionStri ngs>
<clear/>
<add name="Adventure WorksString"
providerName="S ystem.Data.SqlC lient"
connectionStrin g="Data Source=localhos t;
Initial Catalog=Adventu reWorks; Integrated Security=true"/>
</connectionStrin gs>

individualSetti ngs=configurati onManager.Conne ctionStrings[0];

DbConnection MyConnection = null;
switch (individualSett ings.ProviderNa me)
{
case "System.Data.Sq lClient":
MyConnection = new SqlConnection(i ndividualSettin gs.ConnectionSt ring);
break;
case "System.Data.Or acleClient":
MyConnection = new
OracleConnectio n(individualSet tings.Connectio nString);
break;
case "System.Data.Ol eDb":
MyConnection = new OleDbConnection (individualSett ings.Connection String);
break;
case "System.Data.Od bc":
MyConnection = new OdbcConnection( individualSetti ngs.ConnectionS tring);
break;
}

what u need to do in app.cnfig use connection string and based on provider
name u can change the connection type u also need to initialize coomand and
other object u r using.

now when u change the connection string in app.config it generate the
connection, command object based on coonection string.

"Edwin Smith" wrote:
Hello:

I'm using VS2005 with an ODBC database.

I am trying to add a Dialog to an existing Database application to allow the
user to select the database. We have 2 different databases with the same
schema so this is a very desirable function.

I can configure 2 different connection strings in app,config but I can't
figure out how to allow the user to select one or the other.

This should be a simple task but I seem to be missing something. I am very
new to VS2005 so please forgive me for being naïve.

Thanks

Edwin

Oct 26 '07 #2
Just to add a little extra info to the already good reply:
{
ConnectionStrin gSettingsCollec tion connectionStrin gs =
ConfigurationMa nager.Connectio nStrings;

ConnectionStrin gSettings connection;
foreach ( connection in connectionStrin gs) {

string connectionStrin gName = connection.Name ;
string connectionStrin g = connection.Conn ectionString;
string providerName = connection.Prov iderName;

Debug.Print(con nectionStringNa me);
}

this.GridView1. DataSource = connectionStrin gs;
this.GridView1. DataBind();
}

You can bind a grid or anything to these objects above, and get a "picker".
"Som Nath Shukla" <So***********@ discussions.mic rosoft.comwrote in message
news:19******** *************** ***********@mic rosoft.com...
<connectionStri ngs>
<clear/>
<add name="Adventure WorksString"
providerName="S ystem.Data.SqlC lient"
connectionStrin g="Data Source=localhos t;
Initial Catalog=Adventu reWorks; Integrated Security=true"/>
</connectionStrin gs>

individualSetti ngs=configurati onManager.Conne ctionStrings[0];

DbConnection MyConnection = null;
switch (individualSett ings.ProviderNa me)
{
case "System.Data.Sq lClient":
MyConnection = new
SqlConnection(i ndividualSettin gs.ConnectionSt ring);
break;
case "System.Data.Or acleClient":
MyConnection = new
OracleConnectio n(individualSet tings.Connectio nString);
break;
case "System.Data.Ol eDb":
MyConnection = new
OleDbConnection (individualSett ings.Connection String);
break;
case "System.Data.Od bc":
MyConnection = new
OdbcConnection( individualSetti ngs.ConnectionS tring);
break;
}

what u need to do in app.cnfig use connection string and based on provider
name u can change the connection type u also need to initialize coomand
and
other object u r using.

now when u change the connection string in app.config it generate the
connection, command object based on coonection string.

"Edwin Smith" wrote:
>Hello:

I'm using VS2005 with an ODBC database.

I am trying to add a Dialog to an existing Database application to allow
the
user to select the database. We have 2 different databases with the same
schema so this is a very desirable function.

I can configure 2 different connection strings in app,config but I can't
figure out how to allow the user to select one or the other.

This should be a simple task but I seem to be missing something. I am
very
new to VS2005 so please forgive me for being naïve.

Thanks

Edwin


Oct 26 '07 #3
You can make it even easier by using the DbProviderFacto ry class.

individualSetti ngs=configurati onManager.Conne ctionStrings[0];

DbProviderFacto ry factory =
DbProviderFacto ries.GetFactory (individualSett ing.ProviderNam e);
DbConnection MyConnection =
factory.CreateC onnection(indiv idualSettings.C onnectionString );

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"Som Nath Shukla" <So***********@ discussions.mic rosoft.comwrote in
message news:19******** *************** ***********@mic rosoft.com...
<connectionStri ngs>
<clear/>
<add name="Adventure WorksString"
providerName="S ystem.Data.SqlC lient"
connectionStrin g="Data Source=localhos t;
Initial Catalog=Adventu reWorks; Integrated Security=true"/>
</connectionStrin gs>

individualSetti ngs=configurati onManager.Conne ctionStrings[0];

DbConnection MyConnection = null;
switch (individualSett ings.ProviderNa me)
{
case "System.Data.Sq lClient":
MyConnection = new
SqlConnection(i ndividualSettin gs.ConnectionSt ring);
break;
case "System.Data.Or acleClient":
MyConnection = new
OracleConnectio n(individualSet tings.Connectio nString);
break;
case "System.Data.Ol eDb":
MyConnection = new
OleDbConnection (individualSett ings.Connection String);
break;
case "System.Data.Od bc":
MyConnection = new
OdbcConnection( individualSetti ngs.ConnectionS tring);
break;
}

what u need to do in app.cnfig use connection string and based on
provider
name u can change the connection type u also need to initialize coomand
and
other object u r using.

now when u change the connection string in app.config it generate the
connection, command object based on coonection string.

"Edwin Smith" wrote:
>Hello:

I'm using VS2005 with an ODBC database.

I am trying to add a Dialog to an existing Database application to allow
the
user to select the database. We have 2 different databases with the same
schema so this is a very desirable function.

I can configure 2 different connection strings in app,config but I can't
figure out how to allow the user to select one or the other.

This should be a simple task but I seem to be missing something. I am
very
new to VS2005 so please forgive me for being naïve.

Thanks

Edwin

Oct 27 '07 #4
Thanks for the responses everyone. I guess I neglected to mention that my
data set and connections were generated with the VS 2005 designer. I can't
find any of the classes you have mentioned in your responses. To my very
inexperienced brain the designer has obfuscated this beyond belief.

Is there any way to identify the object which contains the information I
need to change?

Thanks

Edwin

"Edwin Smith" <sm**********@a ol.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Hello:

I'm using VS2005 with an ODBC database.

I am trying to add a Dialog to an existing Database application to allow
the user to select the database. We have 2 different databases with the
same schema so this is a very desirable function.

I can configure 2 different connection strings in app,config but I can't
figure out how to allow the user to select one or the other.

This should be a simple task but I seem to be missing something. I am very
new to VS2005 so please forgive me for being naïve.

Thanks

Edwin

Oct 28 '07 #5
OK, I finally I figured out how to change connection strings for datasets
built with the designers.

First, in the Dataset designer window for each table adapter there is a
property called "ConnectionModi fier". This must be set to "
public".

Then each table adapters ConnectionStrin g property can be set as follows:

this.myTableAda pter.Connection .ConnectionStri ng = "Database Name =
MyDatabase; Host = MyHost";

Of coursr the Connection String will be whatever your provider needs. The
queries and provider can still be setup with the GUI tools as before then by
use of the above code can be set to whatever connection string you want.

Edwin
"Edwin Smith" <sm**********@a ol.comwrote in message
news:uE******** ******@TK2MSFTN GP02.phx.gbl...
Thanks for the responses everyone. I guess I neglected to mention that my
data set and connections were generated with the VS 2005 designer. I can't
find any of the classes you have mentioned in your responses. To my very
inexperienced brain the designer has obfuscated this beyond belief.

Is there any way to identify the object which contains the information I
need to change?

Thanks

Edwin

"Edwin Smith" <sm**********@a ol.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>Hello:

I'm using VS2005 with an ODBC database.

I am trying to add a Dialog to an existing Database application to allow
the user to select the database. We have 2 different databases with the
same schema so this is a very desirable function.

I can configure 2 different connection strings in app,config but I can't
figure out how to allow the user to select one or the other.

This should be a simple task but I seem to be missing something. I am
very new to VS2005 so please forgive me for being naïve.

Thanks

Edwin


Nov 12 '07 #6

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

Similar topics

3
5111
by: Ben Binskin | last post by:
Im rather new to developing mysql/php applications and am after some advice on handling user validation for a web based system, ive implimented a number of ways and would like to know which way is better in regards to security etc, here are the following ways i have implimented this in the past: a) user submits via form login/pass, mssql db is accessed via a no login no pass account, and a basic "select from subscribers where user=$blah and...
2
2351
by: hourman | last post by:
We have a web site IIS 5 (on Win2000k) with Oracle 9i backend (Sun unix). There is 1 user ID to oracle(APT_W3) that is used by all users (50). We have a global.asa file that has one APP Start connection string using OLE DB: Application("dbConnString")="Provider=MSDAORA.1;Password='SDERSD';User ID=APT_W3;Data Source=CCEWSDD1_new;Locale Identifier=1033;OLE DB services=-1" The first page that a user sees asks that they select the area...
8
1974
by: rikesh | last post by:
Hi I'm sure this is a very trivial problem! I have a combo bound to a recordset. I was wondering how I can show the value on the page, what the user has selected? The code that I'm using is below. Any help, would be much apprceciated. Kind regards
3
4473
by: teddysnips | last post by:
Currently studying for 70-229. I'm trying to understand how security for users is managed in SQL Server. I've been using SQL Server for a few years now, but without investigating the bits that "just work". So, here's the scenario. This is more or less how I create all my applications (which these days are all ASP.NET). I have a database called "TESTDB" (original, huh?)
4
6057
by: Wonderinguy | last post by:
Our websphere application uses a generic application userid to connect and query db2 on z/os via DB2 connect. The end user,logs in to the application using his regular userid, which is then authenticated with the mainframe and if its ok, then the application proceeds using the generic application id. We are not able to track the user in the DB2 on Mainframe. Is there anyway I can pass the end userid along with the generic userid, so I...
3
10184
by: KemperR | last post by:
Hello Experts outhere, may be someone can tell me whats going wrong with my ADOX trial. I have an Access 2002 database with some tables and queries (views) The code listed below works well up to the point where I want to add the new view to the views collection. I get Runtime error 3001 which is telling me "Arguments are of wrong type,are out of acceptable range or conflict with one another"
1
1815
by: Tim Dol | last post by:
I have inherited a VB6-SP5 program connecting to an Access 2000 database. I'm relatively new to VB/Access programming, so I may overlook something obvious. I'll try to explain the problem I can't solve. My VB executable and Access database are both stored in a shared folder on a Novell volume. The first user has a good performance, but the second user has to wait 9 seconds to open the first form. The third user has to wait 18 seconds,...
1
2117
by: fl | last post by:
I am running ASPNET on my local machine. I have a problem when I try to connect to a SQL server database table. The data looks good when I right click SqlDataAdapter1 to preview the data. When F5 to run it, I get this error "Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection..." Here is my code (they are all generated by the wizard): Public Class WebForm1 Inherits System.Web.UI.Page
1
2435
by: Marc Eggenberger | last post by:
Hi there .. I have the following scenario. I have a Webservice which is running under Win2003/IIS6 with .Net1.1 The Service itselfs connects to a database which is a SQL 2000 on a Server in the same domain. Client is a Windows Form Client (no ASP.NET yet) which connects to the WebService. Before WebService I would make a SQL Server connection with
0
9673
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
9525
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
10452
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
10003
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
9050
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
6785
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
5440
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
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
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

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.