473,386 Members | 1,828 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,386 software developers and data experts.

How to change database name on the fly?

How to change database name on the fly?

I have an asp.net application in which a user connects to a sql server,
where there's a centralized database with the users table and general
settings.
Then, each user also has a database in which his particular information
is stored. There will be a few hundreds of this databases. Certain
groups of users will share a database, all tables in this database have
a userid column for identification which rows are whose. (BTW, this
strange setup is to circunvent the 4GB limit on SQL Server Express,
don't see me, ask my boss).

Now, how do I implement this in asp.net? The web.config contains a
hardcoded connection string, which right now points to the centralized
database and works up to the login point.
After that I don't know what to do next.
I'm using a BLL and DAL layers which points directly to this database
connection string.

I mean, even if I store a second connection string, how am I supposed
to change the databasename ? simple search&replace ?
Are there known techniques, approaches or pattern to do this ?

Sep 14 '06 #1
6 2599
You don't need to and should not change a database name. You don't need
multiple databases. You need to understand how to design databases. If you
need to store information about hundreds of people, you may need several
tables in a single database, but you will only need one record per table per
person. I would suggest downloading the (free) SQL Server Books Online at
http://www.microsoft.com/technet/pro...ads/books.mspx.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.

<cr************@hotmail.comwrote in message
news:11**********************@e63g2000cwd.googlegr oups.com...
How to change database name on the fly?

I have an asp.net application in which a user connects to a sql server,
where there's a centralized database with the users table and general
settings.
Then, each user also has a database in which his particular information
is stored. There will be a few hundreds of this databases. Certain
groups of users will share a database, all tables in this database have
a userid column for identification which rows are whose. (BTW, this
strange setup is to circunvent the 4GB limit on SQL Server Express,
don't see me, ask my boss).

Now, how do I implement this in asp.net? The web.config contains a
hardcoded connection string, which right now points to the centralized
database and works up to the login point.
After that I don't know what to do next.
I'm using a BLL and DAL layers which points directly to this database
connection string.

I mean, even if I store a second connection string, how am I supposed
to change the databasename ? simple search&replace ?
Are there known techniques, approaches or pattern to do this ?

Sep 14 '06 #2
Yikes !!, I'm sorry for the confusion.
I meant to change the database name in the connection string, not to
change the physical name of the database on SQL Server.

But I do need several databases, that's how this was designed. I told
the reason is to circunvent the 4Gb size limit. That's enough reason.
The $6,000 usd price of the standard version is enough reason. More
reason if you have to multplie this for 4-6, while you can have it free
(please, don't ask me use MySQL).

Just to prove I'm not crazy the data model goes like:

LogSettingsDB ( a database)
---- Users Table (a table)
---- Configuration Table
---- Other Table

Log0001DB
---- Logs Table (Stores info of John and Kevin).

Log0002DB
---- Logs Table (Stores info of Paul)

Log0003DB
---- Logs Table (Stores info of Mike, George and Anthony)

Now, the users table goes like (snippet):
-- userID: 1
-- userName: John
-- AsignedDatabase: Log0001DB

Other user:
-- userID: 2
-- userName: Kevin
-- AsignedDatabase: Log0001DB

Other user:
-- userID: 3
-- userName: Paul
-- AsignedDatabase: Log0002DB

Other user:
-- userID: 4
-- userName: Mike
-- AsignedDatabase: Log0003DB
So, after the user is logged and for this it connected to
LogSettingsDB, I need to create/generate/manipulate (this is my
question) another connection string which must be created based on the
"AssignedDatabase" column in the user's settings.
Regards,



Kevin Spencer wrote:
You don't need to and should not change a database name. You don't need
multiple databases. You need to understand how to design databases. If you
need to store information about hundreds of people, you may need several
tables in a single database, but you will only need one record per table per
person. I would suggest downloading the (free) SQL Server Books Online at
http://www.microsoft.com/technet/pro...ads/books.mspx.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.

<cr************@hotmail.comwrote in message
news:11**********************@e63g2000cwd.googlegr oups.com...
How to change database name on the fly?

I have an asp.net application in which a user connects to a sql server,
where there's a centralized database with the users table and general
settings.
Then, each user also has a database in which his particular information
is stored. There will be a few hundreds of this databases. Certain
groups of users will share a database, all tables in this database have
a userid column for identification which rows are whose. (BTW, this
strange setup is to circunvent the 4GB limit on SQL Server Express,
don't see me, ask my boss).

Now, how do I implement this in asp.net? The web.config contains a
hardcoded connection string, which right now points to the centralized
database and works up to the login point.
After that I don't know what to do next.
I'm using a BLL and DAL layers which points directly to this database
connection string.

I mean, even if I store a second connection string, how am I supposed
to change the databasename ? simple search&replace ?
Are there known techniques, approaches or pattern to do this ?
Sep 14 '06 #3
Craig,

For an open connection you can do:
cn.ChangeDatabase(databaseName);

Though... I'm not sure what this would do with connection pooling. If I was
you... I would make certain (SQL Profiler) that a reused connection's
database is being reset (however that works).

You can also manipulate the connection string:

private string FixupConnectionString(string databaseName)
{
string s = ConfigurationManager.ConnectionStrings[0].ConnectionString;

return s.Replace("Initial Catalog=MyNormalDatabase",
"Initial Catalog=" + databaseName);
}
But... this has the feel of just an awful, awful solution.

Why do you need 4 to 6 licenses? Are you sure you need Standard... will
Workgroup do? Are you sure you're company isn't on a licensing plan that
entitles you to a discount (open, select, volume)?

Regards,

Rob MacFadyen


Sep 15 '06 #4
...
<cr************@hotmail.comwrote in message
news:11**********************@e63g2000cwd.googlegr oups.com...
<snip>. (BTW, this
strange setup is to circunvent the 4GB limit on SQL Server Express,
don't see me, ask my boss).
snip
I think this may directly contravene the licence agreement for SQL Server
Express.

Regards,
Ron.
Sep 15 '06 #5
Really ? How ?
Do they limit the number of database as well ?
I read the license, and I didn't see anything regarding the number of
database.
Have you ever read it ?
Anyway, I was not asking legal advise on licensing the database
product, I would go to the SQL Server groups if I wanted that advise.
Thank you.

Regards,

.... wrote:
<cr************@hotmail.comwrote in message
news:11**********************@e63g2000cwd.googlegr oups.com...
<snip>. (BTW, this
strange setup is to circunvent the 4GB limit on SQL Server Express,
don't see me, ask my boss).
snip
I think this may directly contravene the licence agreement for SQL Server
Express.

Regards,
Ron.
Sep 16 '06 #6
...
<cr************@hotmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Really ? How ?
Do they limit the number of database as well ?
I read the license, and I didn't see anything regarding the number of
database.
Have you ever read it ?
Anyway, I was not asking legal advise on licensing the database
product, I would go to the SQL Server groups if I wanted that advise.
Thank you.

Regards,
<snip>
I was not referring to the number of databases, I was referring to section 4
SCOPE OF LICENCE, where it says you may not work around any technical
limitations in the software.
Anyway, good luck in sorting out your problem.
Regards,
Ron.


Sep 16 '06 #7

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

Similar topics

4
by: Sam Fisher | last post by:
Hi, I have a crystal reports hosted on the IIS as web service. Everything works fine except that I can not access the database other than the one on which the report originally created. I am...
4
by: rcmail14872 | last post by:
I have MS SQL Server 2000 evaluation version on my desktop PC. I have the SQL Server client tools (only) on the laptop. The two computers are networked. I had an Access MDB database on my laptop,...
5
by: Hank | last post by:
My Access 2000 code has been running for several years in our main plant. Now we need to install it, as a stand-along application, at remote sites, some of which are out of state. My problem is...
5
by: HS1 | last post by:
Hello I have a datagrid to show data for a database table using "seclect * from tablename" The datagrid works OK. However, I want to change the name of the fields in the database to other...
6
by: Agnes | last post by:
Please help, i had completed over 30-50 reports, now. our client insist to change the database name. anyshorcut that I can change the database name in the report without re-write all of them ??...
2
by: Ryan | last post by:
I'm trying to restore about 70 databases onto a new SQL server and wanted to script the creation and restore. I've done the creation with no problems, but on the restore, the logical names (of the...
10
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
1
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...
1
by: webandwe | last post by:
Hi, Can somebody please show me how to change the connection so I can make it work with my MYSQL database... I just need this login to work then I'm done wiht my project. I don't know what is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.