Showing posts with label purpose. Show all posts
Showing posts with label purpose. Show all posts

Monday, March 19, 2012

DataReader and DataAdapter

Hi,

What is the difference b/w sqldatareader and sqldataadapter? For what purpose are they used in a database connection & how do they differ from each other? Pls explain me in detail.

Regards
Vijay.

Not much to compare about between these two. They are too different from each other.

A SqlDataReader is a data provider that allows a forward-only and read-only access to the data/result set. Meaning that you can't modify any data in the SqlDataReader object and you can only read data sequentially and forward-only. Meaning once you're on the second set of data you can't go back and read the first set. A SqlDataAdapter basically acts like a bridge between a data provider and a dataset. It's what connects your data in its native storage format in the database and your data in a more suitable representation designed for manipulation in your application. Think of it like an interpreter between two people speaking in different languages.

Sunday, February 19, 2012

Database/Query Design Help

I am designing an ASP.NET app that can be used to keep track ofattendance at office hours for a class. The purpose of this isthat we need to know if a student is attending office hours bydifferent people (so that we can flag them as "in trouble"). Idon't know if I have chosen the best database design, and I'm lost asto how to accomplish a query I need.
I have a table HoursAttendance that has the following design.
Column_Name Data_Type Length Allow_Nulls
TA char 4 n
Date smalldatetime 4 n
Start smallint 2 n
End smallint 2 n
Student1 bit 1 y
Student2 bit 1 y
Student3 bit 1 y
Student4 bit 1 y
Student5 bit 1 y
I chose to have the students as columns because the students don'tchange, and then you add rows of office hours. If students arethe rows, then you would be adding columns as the semester continuedwhich I thought was odder...? I'm completely open to suggestionson Database Design, because I really wasn't sure.
Ok, so now I need useful queries. The one that I am stuck on (andalso the first one besides select * from HoursAttendance) is that Iwant the names of Students who have attended more than x officehours. So I need something like
select <column name> from HoursAttendance where count(sum(<column name>)) > x
Granted a better table design could help with this. I'mrelatively new to design, so constructive criticism is desired pleaseSmile [:)]

You can't run a query like that if the students are columnsSmile [:)]. My suggestions:

Students
---
StudentID int
StudentLastName varchar(25)
StudentFirstName varchar(25)
HoursAttendance
------
HoursAttendanceID int
StudentID int
TA char(4)
AttendanceDate smalldatetime
Hours tinyint
Select StudentID, Sum(Hours)
From HoursAttendance
Group By StudentID
Having Sum(Hours) > x
Hope that helps!
Marcie

|||This is why I didn't go with something like what you suggested: It seems with the HoursAttendance table set up like that that it should be broken into an Hours table and an Attendance table.
This seems like way too many tables lol!!
Oh well, I guess.|||Could be -- what would you put in the Hours table vs. the Attendance table? For the most part, trying to cram everything into one table leads to a poor database design (and is not normalized).

This seems like way too many tables lol!!


Scoff...at work I work on a system with several hundred tables, this is nothing! Smile [:)]
Marcie|||

There are 9 TA's that hold weekly office hours. I have a TA table and a DefaultHours table. The DefaultHours table has when the TA normally holds hours (I use this to set selectedValue in time drop down lists. 5-20 students attend each office hour. So that means there are 5-20 rows that have TA, Date, Start, End in common. Which is where I was referring to moving that to a separate table. *shrug*

|||Sure, you could put that in a separate table then:
OfficeHours
----
OfficeHourID int
TA char(4)
Date smalldatetime
Start int
End int
Attendance
----
OfficeHourID
StudentID
Marcie|||I'm just not sure as to what would be the "best" (most efficient in terms of performance and space)
|||Having the extra tables *saves* space because data isn't repeated in any one table. (Normalization) The performance difference between having one HoursAttendance table and splitting them into two would not even be measurable.
Marcie

Database/Log placement

I know that Database 101 required that you place your log files and
your databases on different phyiscal disks for the purpose of disaster
recovery. Does this still hold true if a SAN (EMC) is in the picture?
A client site configured their initial log file drive too
small, and they have proposed moving the logs to the database drive
which has plenty of free space.
They are aware that they will be losing some performance as the log
file drive was on its own spindle for the sequential writes.
TIA,
DaveAn EMC device will be able to protect you against physical failure of the
drives or LUN but can do nothing about the health of the filesystem on which
the database files reside. A corrupted filesystem can get you as badly as a
failed LUN. Having your logs on a different filesystem allows you to
restore to the point of failure by using a BACKUP LOG WITH NO_TRUNCATE if
the LUN with the physical database files goes away. That said, we live in
the real world and many of my client have to keep data files and log files
on the same filesystem. Just keep good backups.
Christian
"Dave" <dderocha@.hotmail.com> wrote in message
news:7e4fb551.0402050821.76b46122@.posting.google.com...
quote:

> I know that Database 101 required that you place your log files and
> your databases on different phyiscal disks for the purpose of disaster
> recovery. Does this still hold true if a SAN (EMC) is in the picture?
> A client site configured their initial log file drive too
> small, and they have proposed moving the logs to the database drive
> which has plenty of free space.
> They are aware that they will be losing some performance as the log
> file drive was on its own spindle for the sequential writes.
> TIA,
> Dave

Database/Log placement

I know that Database 101 required that you place your log files and
your databases on different phyiscal disks for the purpose of disaster
recovery. Does this still hold true if a SAN (EMC) is in the picture?
A client site configured their initial log file drive too
small, and they have proposed moving the logs to the database drive
which has plenty of free space.
They are aware that they will be losing some performance as the log
file drive was on its own spindle for the sequential writes.
TIA,
DaveAn EMC device will be able to protect you against physical failure of the
drives or LUN but can do nothing about the health of the filesystem on which
the database files reside. A corrupted filesystem can get you as badly as a
failed LUN. Having your logs on a different filesystem allows you to
restore to the point of failure by using a BACKUP LOG WITH NO_TRUNCATE if
the LUN with the physical database files goes away. That said, we live in
the real world and many of my client have to keep data files and log files
on the same filesystem. Just keep good backups.
Christian
"Dave" <dderocha@.hotmail.com> wrote in message
news:7e4fb551.0402050821.76b46122@.posting.google.com...
> I know that Database 101 required that you place your log files and
> your databases on different phyiscal disks for the purpose of disaster
> recovery. Does this still hold true if a SAN (EMC) is in the picture?
> A client site configured their initial log file drive too
> small, and they have proposed moving the logs to the database drive
> which has plenty of free space.
> They are aware that they will be losing some performance as the log
> file drive was on its own spindle for the sequential writes.
> TIA,
> Dave

Friday, February 17, 2012

Database Users and Logins

Hi

I can't figure out what the purpose of having seperate users is as I can't actually login to the database using one.

Here is my scenario.

I have a single login called LoginA and I have a database which I want to carve up using schema's. At the database level I need to create a user, associate a login with this user and can set a default schema and specifiy what schemas this USER can access. The login created can access multiple schemas.

So..

I created a database login called loginA.

I created a user for the database called UserA set it's login name to LoginA and

I then created 3 schemas called SchemaA, SchemaB and SchemaC and set their schema owner name to UserA.

I went back to UserA and set their default Schema to SchemaA

How can I login using the new user created as it has no password associated with it. If I login using LoginA then I have no default Schema set becuase the schema is associated with a USER not a LOGIN.

I can understand why you can only have one login account assicated with one user account for each database but I can;t understand why you can specify a user name if you can't use it to login.

Has anyone got any ideas?

Thanks

Logins are used to connect to the server - they provide an identity at the server level. Users provide an identity at the database level. A login will be mapped to a user when he connects to the database.

To have the default schema take effect after login, you should change context to the database where you create UserA (let's say its name is DbA). To automatically do this at login time, you need to additionally change the default database of LoginA to be DbA instead of the master database. A schema is a database entity, so the default schema of a login will be specific to each database to which he will connect.

Thanks
Laurentiu