473,406 Members | 2,343 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,406 software developers and data experts.

sql connection string multiple databases

cj2
If from withing one program I want to access multiple databases on a sql
server do I need to make multiple connections? The connection string
says initial catalog. I'd assume I could denote the database/catalog in
the query but I'm not sure the notation to use.
Nov 12 '08 #1
6 12766
cj2
I don't think I'm interested in that yet.

sloan wrote:
If you need dynamic building...you can consider the

http://www.google.com/search?hl=en&q...nStringBuilder

ConnectionStringBuilder.



"cj2" <cj*@nospam.nospamwrote in message
news:e0**************@TK2MSFTNGP02.phx.gbl...
>If from withing one program I want to access multiple databases on a sql
server do I need to make multiple connections? The connection string says
initial catalog. I'd assume I could denote the database/catalog in the
query but I'm not sure the notation to use.

Nov 13 '08 #2
cj2
Well, actually from playing around I found I could do:

Using mySqlConnection As New SqlConnection("packet
size=4096;......initial catalog=customer")
MySqlReader = New SqlCommand("select count(*) from
[inventory].[dbo].[orders] where ......", mySqlConnection).ExecuteReader
If MySqlReader.HasRows Then
........

So my connection string says the initial catalogue will be the customer
database but the query is actually from the inventory database. This is
what I was asking. I'm open to comments from anyone who wants to share.

sloan wrote:
Yes, each connection string should be unique for each DataStore .
I use DataStore because a connection string can be setup for Databases as
well as TextFiles, ExcelFiles, etc, etc.

..........


"cj2" <cj*@nospam.nospamwrote in message
news:e0**************@TK2MSFTNGP02.phx.gbl...
>If from withing one program I want to access multiple databases on a sql
server do I need to make multiple connections? The connection string says
initial catalog. I'd assume I could denote the database/catalog in the
query but I'm not sure the notation to use.

Nov 13 '08 #3
Hello Chris,

Glad to see you again! Actually, one SqlConnection can only target at one
server database. That is to say, after specifying the database using
Initial catalog in the connection string, the target database is already
determined and cannot be changed. If we want to query from another
database, we have to build another connection string for that new database.

I can understand your concern that you just want to initial the connection
only for the first time, and then you are convenient to query all database
by specifying the database name in query command like we do in the
management studio. But the Visual Studio programming modal is just not
designed to be that way. Different from inside the SQL Server Management
Studio, it is the programmer's duty to navigate to other database by
creating new connection string. And then the query to the new database can
be performed.

Please let me know if you have any future concerns or questions on this,
and I will try my best to follow up.

Have a nice day, Chris!
Best regards,
Ji Zhou (v-****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 14 '08 #4
cj2
I don't understand why you say it will not work. It does. My sql
connection string can say "initial catalog=customer". The I run the
command "select count(*) from [inventory].[dbo].[orders]" which has
nothing to do with the customer database. It is the inventory database.
So in essence I have found I can make one sql connection and reference
any database on that sql server I want using that same connection.
v-****@online.microsoft.com wrote:
Hello Chris,

Glad to see you again! Actually, one SqlConnection can only target at one
server database. That is to say, after specifying the database using
Initial catalog in the connection string, the target database is already
determined and cannot be changed. If we want to query from another
database, we have to build another connection string for that new database.

I can understand your concern that you just want to initial the connection
only for the first time, and then you are convenient to query all database
by specifying the database name in query command like we do in the
management studio. But the Visual Studio programming modal is just not
designed to be that way. Different from inside the SQL Server Management
Studio, it is the programmer's duty to navigate to other database by
creating new connection string. And then the query to the new database can
be performed.

Please let me know if you have any future concerns or questions on this,
and I will try my best to follow up.

Have a nice day, Chris!
Best regards,
Ji Zhou (v-****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 17 '08 #5

"cj2" <cj*@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I don't understand why you say it will not work. It does. My sql
connection string can say "initial catalog=customer". The I run the
command "select count(*) from [inventory].[dbo].[orders]" which has nothing
to do with the customer database. It is the inventory database. So in
essence I have found I can make one sql connection and reference any
database on that sql server I want using that same connection.
v-****@online.microsoft.com wrote:
>Hello Chris, Glad to see you again! Actually, one SqlConnection can only
target at one server database. That is to say, after specifying the
database using Initial catalog in the connection string, the target
database is already determined and cannot be changed. If we want to query
from another database, we have to build another connection string for
that new database.

I can understand your concern that you just want to initial the
connection only for the first time, and then you are convenient to query
all database by specifying the database name in query command like we do
in the management studio. But the Visual Studio programming modal is just
not designed to be that way. Different from inside the SQL Server
Management Studio, it is the programmer's duty to navigate to other
database by creating new connection string. And then the query to the new
database can be performed. Please let me know if you have any future
concerns or questions on this, and I will try my best to follow up.

Have a nice day, Chris!
Best regards,
Ji Zhou (v-****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you.
Please feel free to let my manager know what you think of the level of
service provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues where an initial response from the community or a Microsoft
Support Engineer within 1 business day is acceptable. Please note that
each follow up response may take approximately 2 business days as the
support professional working with you may need further investigation to
reach the most efficient resolution. The offering is not appropriate for
situations that require urgent, real-time or phone-based interactions or
complex project analysis and dump analysis issues. Issues of this nature
are best handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
================================================= =
This posting is provided "AS IS" with no warranties, and confers no
rights.
This is (has been) what you could do in SQL Server from v4.2. What you are
finding is that you are using a user account that allows access to both
databases. Hey you can add a linked server and get data from another
database server entirely.

LS

Nov 17 '08 #6
cj2
Yes, the user name as far as I'm concerned is for the server as a whole
and is good for any database on the server. I hadn't thought about it,
but of course there might be places that give out user names for
individual databases and I can see where that would require a separate
connection per database. Thanks for the clarification.
Lloyd Sheen wrote:
>
"cj2" <cj*@nospam.nospamwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I don't understand why you say it will not work. It does. My sql
connection string can say "initial catalog=customer". The I run the
command "select count(*) from [inventory].[dbo].[orders]" which has
nothing to do with the customer database. It is the inventory
database. So in essence I have found I can make one sql connection and
reference any database on that sql server I want using that same
connection.
v-****@online.microsoft.com wrote:
>>Hello Chris, Glad to see you again! Actually, one SqlConnection can
only target at one server database. That is to say, after specifying
the database using Initial catalog in the connection string, the
target database is already determined and cannot be changed. If we
want to query from another database, we have to build another
connection string for that new database.

I can understand your concern that you just want to initial the
connection only for the first time, and then you are convenient to
query all database by specifying the database name in query command
like we do in the management studio. But the Visual Studio
programming modal is just not designed to be that way. Different
from inside the SQL Server Management Studio, it is the programmer's
duty to navigate to other database by creating new connection string.
And then the query to the new database can be performed. Please let
me know if you have any future concerns or questions on this, and I
will try my best to follow up.

Have a nice day, Chris!
Best regards,
Ji Zhou (v-****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments
and suggestions about how we can improve the support we provide to
you. Please feel free to let my manager know what you think of the
level of service provided. You can send feedback directly to my
manager at: ms****@microsoft.com.

================================================ ==
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues where an initial response from the community or a Microsoft
Support Engineer within 1 business day is acceptable. Please note
that each follow up response may take approximately 2 business days
as the support professional working with you may need further
investigation to reach the most efficient resolution. The offering is
not appropriate for situations that require urgent, real-time or
phone-based interactions or complex project analysis and dump
analysis issues. Issues of this nature are best handled working with
a dedicated Microsoft Support Engineer by contacting Microsoft
Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.

================================================ ==
This posting is provided "AS IS" with no warranties, and confers no
rights.

This is (has been) what you could do in SQL Server from v4.2. What you
are finding is that you are using a user account that allows access to
both databases. Hey you can add a linked server and get data from
another database server entirely.

LS
Nov 17 '08 #7

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

Similar topics

2
by: TS | last post by:
Does anyone have any experience creating an ODBC Connection to multiple Access databases? I need to be able to connect several databases, rather than linking to the tables. My only experience...
3
by: DKode | last post by:
I am preparing to build an app that will pull data from multiple databases on the same sql server. For performance sake, is there a more "effecient" way to grab data from multiple databases at...
1
by: booksnore | last post by:
I have an application where a have a single admin database and multiple customer databases containing the customer's warehouse data. In the admin database I hold a user table and also a client...
9
by: TC | last post by:
I need to design a system which represents multiple "projects" in SQL Server. Each project has the same data model, but is independent of all others. My inclination is to use one database to store...
3
by: Sankalp | last post by:
Currently I am developing a advanced VB 2005 application which Display's/ Updates / (Creates New ) data in the database. For this purpose I am using databound controls, i.e. all my datagrids,...
13
by: Jennifer.Berube | last post by:
well I'm not sure how to go about making my SQL connection string... The code below is what I need to replace with my SQL connection...I just don't know if that code is for DSN or access... I...
2
by: Orit | last post by:
Hello . Please find below my questions - I hope some of the ASP.NET experts of this forum will answer to those beginner's questions : My Web site should be able to work with either SQL Server...
4
by: David W | last post by:
We have a setup where we have a single web application, but the user can be attached to any of a hundred different (identically structured) databases depending on their login credentials. ...
0
by: sloan | last post by:
Yes, each connection string should be unique for each DataStore . I use DataStore because a connection string can be setup for Databases as well as TextFiles, ExcelFiles, etc, etc. ........... ...
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
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,...
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...
0
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,...

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.