Showing posts with label client. Show all posts
Showing posts with label client. Show all posts

Sunday, March 25, 2012

Database for multiple clients

I have a SQL Server 2005 Express database that was designed to be used by one client. What is the best way to change the design so it can contain multiple clients that can only see data entered by users of each client organization?

Also I'm using the asp.net membership database to handle login and profiles. Can this be used with my multi client database?

Let's say you have TableA that contains data for one client. You intend to change the design to include data for multiple clients, where each client sees their own data.

Here are classic database design steps to follow in this situation

1. Create a reference table that holds the organization name and a unique ID for each organization - let's say that field is called organization_id

2. Add a record per organization to this table.

3. Add the field organization_id to TableA and set the value to 1 for all existing records

4. All future records added into TableA must have the correct organization_id value.

5. Create a View that restricts data in TableA to a specific organization_id.

6. Change your application to ensure that all data access is done via views that are restricted on organization_id

That's a kind of summary of what you're looking for. I repeat that using Views are the standard way of ensuring that clients only see their relevant data.

For your second question - certainly you may use login and profiles. I have implemented this kind of design by using Roles (aspnet_roles) as the reference table I mention in step 1 and 2. So you create a role per organization. Then add RoleID to your other tables as in step 3.

|||

Thank you very much for this information.

Is it possible to use my current aspnet_database as you mentioned, even if I already use roles for limiting user access to pages in the application? Also the application uses stored procedures to insert,update, and delete date.

Thanks again for your good thoughts,

|||

Yes, it's possible to use a current security database even if you already use roles. Users can be in more than one role. So keep your existing roles, and create additional roles for the organizations. Presumably all your current users are from one organization (your first), so add them into the correct new role - that won't effect the existing user access limits.

Great that the application uses stored procedures - that is already a sign of good design. There are several ways to incorporate multiple clients here. You could add a parameter to your stored procedures which accepts the correct RoleID and ensures that the new column is maintained correctly. Note that if your procedures already accept a UserID, then you don't have to change the parameter list - within the stored proc you can do a lookup of the correct RoleID.

Note that changing the stored procedure interface will need corresponding changes to all your client code - and regression testing. Another option depends on how your application connects to the database - if you are using a common login to the database for all users this is not an option, but if you are using user logins (individual logins and passwords for your users), then you can programmatically determine within the stored procedure who is logged in (using a system function) and then get the RoleID.

Good luck! By the way, if you extending the application for somebody else (your manager or a client), make sure they understand that changing from single to multiple clients is a significant change to an application - don't sell yourself short!

sql

Wednesday, March 21, 2012

Database Engine Worker thread pool : Queue length

Hello,
When the "Max Worker Threads" parameter is lower than the number of client
connections, SQL Server pools the worker threads. Is there a performance
counter to see the worker thread pool queue length (connections waiting a
thread to handle requests)?
TIA.There is Server Work Queues - Queue Length counter , which gives the
current length of the server queue related to this CPU>.
--
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
"Olivier Matrot" <olivier.matrot.rte@.online.nospam> wrote in message
news:#1OEG3RvGHA.1296@.TK2MSFTNGP02.phx.gbl...
> Hello,
> When the "Max Worker Threads" parameter is lower than the number of client
> connections, SQL Server pools the worker threads. Is there a performance
> counter to see the worker thread pool queue length (connections waiting a
> thread to handle requests)?
> TIA.
>|||Is this related to SQL Server ? What I want to know is the number of "work
items" (SQL Commands) waiting to be dispatched to the thread pool. It gives
an accurate value of the amout of work requested, wich can be used to
properly size the number of Threads/CPU needed to handle the workload
without eating 100% of the CPU.
"Jack Vamvas" <DEL_TO_REPLYtechsupport@.ciquery.com> wrote in message
news:RvydnVZuaLzD2EHZnZ2dnUVZ8qadnZ2d@.bt.com...
> There is Server Work Queues - Queue Length counter , which gives the
> current length of the server queue related to this CPU>.
> --
> Jack Vamvas
> ___________________________________
> Receive free SQL tips - www.ciquery.com/sqlserver.htm
> ___________________________________
>
> "Olivier Matrot" <olivier.matrot.rte@.online.nospam> wrote in message
> news:#1OEG3RvGHA.1296@.TK2MSFTNGP02.phx.gbl...
>> Hello,
>> When the "Max Worker Threads" parameter is lower than the number of
>> client
>> connections, SQL Server pools the worker threads. Is there a performance
>> counter to see the worker thread pool queue length (connections waiting a
>> thread to handle requests)?
>> TIA.
>>
>|||If it's SQL2005, something like the following may be useful:
select
scheduler_id,
current_tasks_count,
runnable_tasks_count,
current_workers_count,
active_workers_count,
work_queue_count,
load_factor
from sys.dm_os_schedulers
where scheduler_id < 255
Pay attention to the work_queue_count value.
Linchi
"Olivier Matrot" wrote:
> Is this related to SQL Server ? What I want to know is the number of "work
> items" (SQL Commands) waiting to be dispatched to the thread pool. It gives
> an accurate value of the amout of work requested, wich can be used to
> properly size the number of Threads/CPU needed to handle the workload
> without eating 100% of the CPU.
> "Jack Vamvas" <DEL_TO_REPLYtechsupport@.ciquery.com> wrote in message
> news:RvydnVZuaLzD2EHZnZ2dnUVZ8qadnZ2d@.bt.com...
> > There is Server Work Queues - Queue Length counter , which gives the
> > current length of the server queue related to this CPU>.
> > --
> > Jack Vamvas
> > ___________________________________
> > Receive free SQL tips - www.ciquery.com/sqlserver.htm
> > ___________________________________
> >
> >
> > "Olivier Matrot" <olivier.matrot.rte@.online.nospam> wrote in message
> > news:#1OEG3RvGHA.1296@.TK2MSFTNGP02.phx.gbl...
> >> Hello,
> >> When the "Max Worker Threads" parameter is lower than the number of
> >> client
> >> connections, SQL Server pools the worker threads. Is there a performance
> >> counter to see the worker thread pool queue length (connections waiting a
> >> thread to handle requests)?
> >> TIA.
> >>
> >>
> >
> >
>
>|||Very interesting.
Thanks for that.
"Linchi Shea" <LinchiShea@.discussions.microsoft.com> wrote in message
news:F08138DD-A908-4295-AEDA-DE39C9C745EF@.microsoft.com...
> If it's SQL2005, something like the following may be useful:
> select
> scheduler_id,
> current_tasks_count,
> runnable_tasks_count,
> current_workers_count,
> active_workers_count,
> work_queue_count,
> load_factor
> from sys.dm_os_schedulers
> where scheduler_id < 255
> Pay attention to the work_queue_count value.
> Linchi
> "Olivier Matrot" wrote:
>> Is this related to SQL Server ? What I want to know is the number of
>> "work
>> items" (SQL Commands) waiting to be dispatched to the thread pool. It
>> gives
>> an accurate value of the amout of work requested, wich can be used to
>> properly size the number of Threads/CPU needed to handle the workload
>> without eating 100% of the CPU.
>> "Jack Vamvas" <DEL_TO_REPLYtechsupport@.ciquery.com> wrote in message
>> news:RvydnVZuaLzD2EHZnZ2dnUVZ8qadnZ2d@.bt.com...
>> > There is Server Work Queues - Queue Length counter , which gives
>> > the
>> > current length of the server queue related to this CPU>.
>> > --
>> > Jack Vamvas
>> > ___________________________________
>> > Receive free SQL tips - www.ciquery.com/sqlserver.htm
>> > ___________________________________
>> >
>> >
>> > "Olivier Matrot" <olivier.matrot.rte@.online.nospam> wrote in message
>> > news:#1OEG3RvGHA.1296@.TK2MSFTNGP02.phx.gbl...
>> >> Hello,
>> >> When the "Max Worker Threads" parameter is lower than the number of
>> >> client
>> >> connections, SQL Server pools the worker threads. Is there a
>> >> performance
>> >> counter to see the worker thread pool queue length (connections
>> >> waiting a
>> >> thread to handle requests)?
>> >> TIA.
>> >>
>> >>
>> >
>> >
>>|||What would be the command for SQL 2000 i like to monitor this aswell.
How often to run say once hour
Thanks

Monday, March 19, 2012

Database Encryption

Hello All,
Is there a built-in way that one can encrypt and decrypt data in SQL
Server tables. My client wants all data in the database encrypted so that
even the system admins doing backups cannot view the sensitive data.
Any suggestions or solutions will be greatly appreciated.
Thanks a lot,
Imran.What version of SQL Server, 2000 or 2005..?
--
HTH. Ryan
"Imran Aziz" <imran@.tb2.net> wrote in message
news:Omk%23c3gjGHA.1552@.TK2MSFTNGP03.phx.gbl...
> Hello All,
> Is there a built-in way that one can encrypt and decrypt data in SQL
> Server tables. My client wants all data in the database encrypted so that
> even the system admins doing backups cannot view the sensitive data.
> Any suggestions or solutions will be greatly appreciated.
> Thanks a lot,
> Imran.
>
>|||Hello Ryan thanks for your response. I will be using SQL Server 2005,
googling around I can see that SQL Server 2005 has this option , but I
cannot seem to see how to work with it in our install of SQL Server 2005.
In addition the current database is in SQL Server 2000 which I will
transfer to SQL Server 2005 and then would like to encrypt all existing data
in the database.
Of some info that I have found till now, it seems that one has to set the
encryption up for a database table on creation (although could not find it
in my SQL server 2005)
but will SQL Server 2005 encrypt existing data in tables ?
Thanks a lot,
Imran.
"Ryan" <Ryan_Waight@.nospam.hotmail.com> wrote in message
news:eZmEVchjGHA.1600@.TK2MSFTNGP04.phx.gbl...
> What version of SQL Server, 2000 or 2005..?
> --
> HTH. Ryan
>
> "Imran Aziz" <imran@.tb2.net> wrote in message
> news:Omk%23c3gjGHA.1552@.TK2MSFTNGP03.phx.gbl...
>> Hello All,
>> Is there a built-in way that one can encrypt and decrypt data in SQL
>> Server tables. My client wants all data in the database encrypted so that
>> even the system admins doing backups cannot view the sensitive data.
>> Any suggestions or solutions will be greatly appreciated.
>> Thanks a lot,
>> Imran.
>>
>

Wednesday, March 7, 2012

Database Design Questions

I'm trying to design a database that allows the users to give each individual client/company unlimited addresses and salutations. I can build the design that accommodates this, but I cannot figure out how to handle them knowing which salutation to use with a mailing they might do to the clients.

I have put the Company Name and Position (title) in the address table so that when doing a mailing the company name and title are associated with the company address being mailed too. But again, I'm not sure how they would choose a salutation if they have many choices.

Looking for any of your thoughts or suggestions.

Thank you,I'm not following you 100%, but I'll take a stab at something that might accomodate your needs:

COMPANY
id_company
company_name

COMPANY_ADDRESS
id_company_address
id_company
address_company_name
address1
address2
city
state
zip

COMPANY_SALUTATION
id_company_salutation
id_company
salutation

COMPANY_MAILING
id_company_mailing
id_company
id_company_address
id_company_salutation

When they are about to do a mailing, the COMPANY_MAILING table should be populated as desired for each company involved in the mailing.

Terri

Saturday, February 25, 2012

Database design question

I have a database that allows a client to have many addresses some are examples would be Home, Office, Vacation Home, etc... If we are mailing to a home address we would not want to the company name or title fields to be included, oh yah all files are exported to Excel for merging. I would like to put the company name and title fields in the address table so if we are mailing to a business or office the company name and title go with it, and if it is an address other than a business or office the company name and title are blank.

Does this really break any kind of rules, if we look at it as I have stated here?

Thanks for any thoughts,Yes. It is definitely breaking rules, the rules or normalization, and my guess is that you realize this or you would not be asking this question.

And sooner or later, making a bad design choice like this will come back to haunt you.

Have an Address table, and a Person table, and a Company table, and a PersonType table, and set the attributes accordningly. The query to get the data will be a bit more complex, but you'll reap the benefits of increased data integrity for a long time...|||So if I have a design like the following, how would you suggest that I exclude the companyName and ClientTitle if I'm mailing to a home address and the client has a home and company address in the address table? Thanks for your thoughts again.

tblClients
ClientID
ClientType = Indivudal or Company, etc...
CompanyName
ClientTitle

tblAddresses
AddressID
ClientID

tblClientTypeLookup = Individual, Company, etc...

Friday, February 24, 2012

database design for fast client updates

I'm trying to work out a database design to make it quicker for my client
program to read and display updates to the data set. Currently it reads in
the entire data set again after each change, which was acceptable when the
data set was small but now it's large enough to start causing noticable
delays. I've come up with a possible solution but am looking for others'
input on its suitability to the problem.

Here is the DDL for one of the tables:

create table epl_packages
(
customer varchar(8) not null, -- \
package_type char not null, -- primary key
package_no int not null, -- /
dimensions varchar(50) not null default(0),
weight_kg int not null,
despatch_id int, -- filled in on despatch
loaded bit not null default(0),
item_count int not null default(0)
)

alter table epl_packages
add constraint pk_epl_packages
primary key (customer, package_type, package_no)

My first thought was to add a datetime column to each table to record the
time of the last change, but that would only work for inserts and updates.
So I figured that a separate table for deletions would make this complete.
DDL would be something like:

create table epl_packages
(
customer varchar(8) not null,
package_type char not null,
package_no int not null,
dimensions varchar(50) not null default(0),
weight_kg int not null,
despatch_id int,
loaded bit not null default(0),
item_count int not null default(0),
last_update_time datetime default(getdate()) -- new column
)

alter table epl_packages
add constraint pk_epl_packages
primary key (customer, package_type, package_no)

create table epl_packages_deletions
(
delete_time datetime,
customer varchar(8) not null,
package_type char not null,
package_no int not null
)

And then these triggers on update and delete (insert is handled automatically
by the default constraint on last_update_time):

create trigger tr_upd_epl_packages
on epl_packages
for update
as
-- check for primary key change
if (columns_updated() & 1792) > 0 -- first three columns: 256+512+1024
insert epl_packages_deletions
select
getdate(),
customer,
package_type,
package_no
from deleted

update A
set last_update_time = getdate()
from epl_packages A
join inserted B
on A.customer = B.customer and
A.package_type = B.package_type and
A.package_no = B.package_no
go

create trigger tr_del_epl_packages
on epl_packages
for delete
as
insert epl_packages_deletions
select
getdate(),
customer,
package_type,
package_no
from deleted
go

The client program would then do the initial read as follows:

select getdate()

select
customer,
package_type,
package_no,
dimensions,
weight_kg,
despatch_id,
loaded,
item_count
from epl_packages
where
customer = {current customer}
order by
customer,
package_type,
package_no

It would store the output of getdate() to be used in subsequent updates,
which would be read from the server as follows:

select getdate()

select
customer,
package_type,
package_no,
dimensions,
weight_kg,
despatch_id,
loaded,
item_count
from epl_packages
where
customer = {current customer} and
last_update_time > {output of getdate() from previous read}
order by
customer,
package_type,
package_no

select
customer,
package_type,
package_no
from epl_packages_deletions
where
customer = {current customer} and
delete_time > {output of getdate() from previous read}

The client program will then apply the deletions and the updated/inserted
rows, in that order. This would be done for each table displayed in the
client.

Any critical comments on this approach and any improvements that could
be made would be much appreciated!T.H.N. wrote:
> I'm trying to work out a database design to make it quicker for my client
> program to read and display updates to the data set. Currently it reads in
> the entire data set again after each change, which was acceptable when the
> data set was small but now it's large enough to start causing noticable
> delays. I've come up with a possible solution but am looking for others'
> input on its suitability to the problem.

Use stored procedures for your updates, inserts, deletes and selects.
As far as I can see you aren't doing that now. Is there a reason why
not?

If you use procs then you won't need the triggers, you probably won't
need two tables and you'll probably see a performance improvement along
with all the other benefits of procs.

Thanks for including the DDL. Always tell us what version you are using
as well - it does help.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/...US,SQL.90).aspx

--|||David Portas wrote:

> Use stored procedures for your updates, inserts, deletes and selects.
> As far as I can see you aren't doing that now. Is there a reason why
> not?
> If you use procs then you won't need the triggers, you probably won't
> need two tables and you'll probably see a performance improvement along
> with all the other benefits of procs.
> Thanks for including the DDL. Always tell us what version you are using
> as well - it does help.

Thanks for your advice. The reason I used triggers for this is that it was
easier to test approach this out without modifying the existing client
program, which uses a mix of stored procs and direct SQL statements -
something I do need to fix!

Regarding performance improvements - my goal is to make the time it takes
to refresh the client's displayed data set relative to the amount of changes
since the last refresh, rather than the size of the entire set. So I think
I do need an auxillary table as I can't see any other way of logging the
deletions.

I'm using SQL Server 2000, sorry for not including that in my original post!|||T.H.N. (newsgroup.replies@.spam.la) writes:
> I'm trying to work out a database design to make it quicker for my client
> program to read and display updates to the data set. Currently it reads in
> the entire data set again after each change, which was acceptable when the
> data set was small but now it's large enough to start causing noticable
> delays. I've come up with a possible solution but am looking for others'
> input on its suitability to the problem.

I assume that these updates are not performed by your client program,
but by some other process?

Rather than using a datetime column, you could use a timestamp column.
A timestamp column is automatically updated with a monotonically
increasing value each time a row is inserted or updated. Each value is
unique in the database. Note that the name of the type is misleading.
The value is a binary(8) and has to relation to time.

You would still need that table for deleted rows. (Unless you add a
"deleted" bit to the table; the client program would then actually
perform the deletion once it has consumed the update.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland Sommarskog wrote:
> I assume that these updates are not performed by your client program,
> but by some other process?
> Rather than using a datetime column, you could use a timestamp column.
> A timestamp column is automatically updated with a monotonically
> increasing value each time a row is inserted or updated. Each value is
> unique in the database. Note that the name of the type is misleading.
> The value is a binary(8) and has to relation to time.
> You would still need that table for deleted rows. (Unless you add a
> "deleted" bit to the table; the client program would then actually
> perform the deletion once it has consumed the update.

Yes, sort of - there are several client programs all operating on the same
data set.

Thanks for pointing me to the timestamp data type, it's much better for this!
As well as its uniqueness per change I find it preferable to datetime as it's
independent of the system clock. My DDL now looks like this:

create table epl_packages
(
customer varchar(8) not null,
package_type char not null,
package_no int not null,
dimensions varchar(50) not null default(0),
weight_kg int not null,
despatch_id int,
loaded bit not null default(0),
item_count int not null default(0),
ts_last_update timestamp
)

alter table epl_packages
add constraint pk_epl_packages
primary key (customer, package_type, package_no)

create table epl_packages_deletions
(
ts_delete timestamp primary key, -- generated on insert. ok for PK as
-- there will be no updates to this table
customer varchar(8) not null,
package_type char not null,
package_no int not null
)

The triggers have less to do:

create trigger tr_del_epl_packages
on epl_packages
for delete
as
insert epl_packages_deletions
values (
customer,
package_type,
package_no
)
select
customer,
package_type,
package_no
from deleted
go

create trigger tr_upd_epl_packages
on epl_packages
for update
as
-- check for primary key change
if (columns_updated() & 1792) > 0 -- first three columns: 256+512+1024
insert epl_packages_deletions
values (
customer,
package_type,
package_no
)
select
customer,
package_type,
package_no
from deleted

And the client program uses "select @.@.dbts" prior to reading the data set or
changes to it to determine the point at which its displayed data was current.

Friday, February 17, 2012

database creation in XP

I am an SQL beginer, and have installed SQL 2000 in Windows XP SP2. Only the client components of SQL were installed by default in XP. SQL query analyser doesnot detect any servers (I already have IIS installed). In such a scenario how do I create a Database and gain access to it ?Do you know SQL server name?|||

Quote:

Originally Posted by iburyak

Do you know SQL server name?


No. The SQL Query analyser doesnot show any available servers. Also I am not connected to any networked PC. I wish to connect to the local/virtual server in IIS in C drive. I have an ASP.Net application in my wwwroot forlder for which I need to create a database to store and access data. Please note that while installing SQL server in XP I was prompted with the following message: "Microsoft SQL Server 2000 Enterprise Edition server component is not suported on this operating system. Only client components will be available for installation". Also due to this reason the MSSQL server service has not been installed.|||IIS server is a web server and not SQL server.
As far as I understand you didn't install SQL server at all and this is why you can't connect to it.

The only option you have is to use Access database instead. Go to Microsoft Office and you will be able to find it.|||

Quote:

Originally Posted by iburyak

IIS server is a web server and not SQL server.
As far as I understand you didn't install SQL server at all and this is why you can't connect to it.

The only option you have is to use Access database instead. Go to Microsoft Office and you will be able to find it.


Yes you were right. Although SQL was installed the server components were not installed. I have added the server components and now its working fine.
Thanks a lot.