Showing posts with label refresh. Show all posts
Showing posts with label refresh. Show all posts

Monday, March 19, 2012

Active Directory, Terminated Employees

Hello, we have scheduled a nightly refresh into an Employees table in a
database, that receives data from Active Directory. AD is the "authority" o
f
who is an active employee and frees us from manual maintenance of the
Employees table in our DB. However, we want to store information on
employees who resign, retire etc. and don't want orphaned records (this is a
training database storing information on what employees take what classes,
with dates and costs). I'd like to set up some kind of append query but
unlike Access, SQL would not let me append duplicate records. The database
has a termination date field also. Any suggestions would be appreciated.
Thanks, Pancho.Do you want only one row per employee, or one for every change in the
employee data?
Are you only updating the termination date from AD, or are you loading all
of the employee data from AD?
Please include DDL and more detail.
(explained here)
http://www.aspfaq.com/etiquette.asp?id=5006
"Pancho" <Pancho@.discussions.microsoft.com> wrote in message
news:4FBC26F2-F086-4734-8A2B-06CC11525F36@.microsoft.com...
> Hello, we have scheduled a nightly refresh into an Employees table in a
> database, that receives data from Active Directory. AD is the "authority"
of
> who is an active employee and frees us from manual maintenance of the
> Employees table in our DB. However, we want to store information on
> employees who resign, retire etc. and don't want orphaned records (this is
a
> training database storing information on what employees take what classes,
> with dates and costs). I'd like to set up some kind of append query but
> unlike Access, SQL would not let me append duplicate records. The
database
> has a termination date field also. Any suggestions would be appreciated.
> Thanks, Pancho.|||Jim,
We only want one row per employee. To the table structure depicted in the
script below I would ideally like to add a date/time column named TermDate.
If empty the employee would be still active.
Thank you for the etiquette link. The programmer kept default length 255's
on varchars. In reality our EmpNumbers are only 3-4 characters, not 50. In
our employee population, we have some employees who leave to go to college
and then return, and we typically preserve their old employee number, and
reactivate it when they return.
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[Employees]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Employees]
GO
CREATE TABLE [dbo].[Employees] (
[FullName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[LName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Extension] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[EmpNumber] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Email] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Company] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Department] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
"Jim Underwood" wrote:

> Do you want only one row per employee, or one for every change in the
> employee data?
> Are you only updating the termination date from AD, or are you loading all
> of the employee data from AD?
> Please include DDL and more detail.
> (explained here)
> http://www.aspfaq.com/etiquette.asp?id=5006
>
> "Pancho" <Pancho@.discussions.microsoft.com> wrote in message
> news:4FBC26F2-F086-4734-8A2B-06CC11525F36@.microsoft.com...
> of
> a
> database
>
>|||OK, so you need to add a column to your table:
alter table [dbo].[Employees]
add TerminationDate datetime;
Then you need to update this table on a periodic basis? I have not worked
much with AD in SQL Server, but lets assume you are connected and querying
AD as you would a table. We'll call the "table" ADEmpData, and assume it
has EmpNumber and TerminationDate as columns. Also assume EmpNumber can be
duplicated in AD, but it is the PK (or at least unique) in the Employees
table. If you can explain how you are connecting to AD, someone may be able
to provide more complete code.
Update Employees as Emp
set Emp.TerminationDate = (
select top 1 AD.TerminationDate
from ADEmpData as AD
Where AD.EmpNumber = Emp.EmpNumber
order by AD.TerminationDate
-- the above added just to give consistent results with TOP
)
and exists (select 1
from ADEmpData as AD
Where AD.EmpNumber = Emp.EmpNumber)
-- exists used to only attempt to update values if the emp
-- exists in AD
Note that AD may store term date as a string, not a date type, so you may
have to do some conversion here.
"Pancho" <Pancho@.discussions.microsoft.com> wrote in message
news:79A765A9-80AE-4B80-BD4F-106AB1CB636C@.microsoft.com...
> Jim,
> We only want one row per employee. To the table structure depicted in the
> script below I would ideally like to add a date/time column named
TermDate.
> If empty the employee would be still active.
> Thank you for the etiquette link. The programmer kept default length
255's
> on varchars. In reality our EmpNumbers are only 3-4 characters, not 50.
In
> our employee population, we have some employees who leave to go to college
> and then return, and we typically preserve their old employee number, and
> reactivate it when they return.
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[Employees]') and OBJECTPROPERTY(id, N'IsUserTable') =
1)
> drop table [dbo].[Employees]
> GO
> CREATE TABLE [dbo].[Employees] (
> [FullName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
> [LName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [FName] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Extension] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Description] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [EmpNumber] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Email] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Company] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
> [Department] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
> ) ON [PRIMARY]
> GO
>
> "Jim Underwood" wrote:
>
all
a
"authority"
(this is
classes,
but
appreciated.|||Jim,
This is good information and I appreciate the detail. This will probably
work here. Have a nice wend! Pancho.
"Jim Underwood" wrote:

> OK, so you need to add a column to your table:
> alter table [dbo].[Employees]
> add TerminationDate datetime;
> Then you need to update this table on a periodic basis? I have not worked
> much with AD in SQL Server, but lets assume you are connected and querying
> AD as you would a table. We'll call the "table" ADEmpData, and assume it
> has EmpNumber and TerminationDate as columns. Also assume EmpNumber can b
e
> duplicated in AD, but it is the PK (or at least unique) in the Employees
> table. If you can explain how you are connecting to AD, someone may be ab
le
> to provide more complete code.
> Update Employees as Emp
> set Emp.TerminationDate = (
> select top 1 AD.TerminationDate
> from ADEmpData as AD
> Where AD.EmpNumber = Emp.EmpNumber
> order by AD.TerminationDate
> -- the above added just to give consistent results with TOP
> )
> and exists (select 1
> from ADEmpData as AD
> Where AD.EmpNumber = Emp.EmpNumber)
> -- exists used to only attempt to update values if the emp
> -- exists in AD
> Note that AD may store term date as a string, not a date type, so you may
> have to do some conversion here.
> "Pancho" <Pancho@.discussions.microsoft.com> wrote in message
> news:79A765A9-80AE-4B80-BD4F-106AB1CB636C@.microsoft.com...
> TermDate.
> 255's
> In
> 1)
> all
> a
> "authority"
> (this is
> classes,
> but
> appreciated.
>
>|||Glad if I could help.
Please remember to post your final solution so others who have a similar
issue will be able to learn from it.
Also, I am interested in seeing how you handle the AD connection. Thus far
I have only done it via VB.Net and have not connected via SQL Server.
"Pancho" <Pancho@.discussions.microsoft.com> wrote in message
news:84DA9C84-4201-4766-9ADC-FD74F3EB5DED@.microsoft.com...
> Jim,
> This is good information and I appreciate the detail. This will probably
> work here. Have a nice wend! Pancho.
> "Jim Underwood" wrote:
>
worked
querying
it
be
able
may
the
50.
college
and
=
NULL ,
,
NULL ,
the
loading
in
the
on
query|||We use a scheduled DTS package to import a .csv file. The .csv file is
exported nightly using a scheduled .bat file that calls a .vbs script that
performs the export from AD. We're not going to implement the TermDate just
yet but I will post the outcome when we do. Thanks again, P.
"Jim Underwood" wrote:

> Glad if I could help.
> Please remember to post your final solution so others who have a similar
> issue will be able to learn from it.
> Also, I am interested in seeing how you handle the AD connection. Thus fa
r
> I have only done it via VB.Net and have not connected via SQL Server.
>
> "Pancho" <Pancho@.discussions.microsoft.com> wrote in message
> news:84DA9C84-4201-4766-9ADC-FD74F3EB5DED@.microsoft.com...
> worked
> querying
> it
> be
> able
> may
> the
> 50.
> college
> and
> =
> NULL ,
> ,
> NULL ,
> the
> loading
> in
> the
> on
> query
>
>|||You might check out microsoft.public.active.directory.interfaces to see if
you can use a more direct approach. I believe SQL Server allows you to
query AD directly, which could eliminate the need for the VBS, BAT, CSV,
etc. I do not know how much is implemented in 2000 VS 2005, but I think I
have seen some examples in this forum.
"Pancho" <Pancho@.discussions.microsoft.com> wrote in message
news:931B3577-C055-4184-AEF5-AC0D22D9652E@.microsoft.com...
> We use a scheduled DTS package to import a .csv file. The .csv file is
> exported nightly using a scheduled .bat file that calls a .vbs script that
> performs the export from AD. We're not going to implement the TermDate
just
> yet but I will post the outcome when we do. Thanks again, P.
> "Jim Underwood" wrote:
>
far
probably
assume
can
Employees
be
you
depicted in
length
not
number,
N'IsUserTable')
NOT
,
,
NULL
NULL ,
,
NULL ,
NULL
in
table
of
information
records
what
The

Tuesday, March 6, 2012

Accumulating snapshot folder

Hi all,
I found that my testing server is accumulating shapshot folder in repldata. Everytime, we refresh the tables (snapshot publication), a new folder created without the old folders. And I found that there is at most 1 snapshot folder remain in production server. Any parameter to adjust the retention period of the snapshot folder? Thanks in advanceWhat version of SQL Server are you using?|||MSSQL2005 SP2|||Retention setting can be adjusted in publication property.

accumulating shapshot folder in repldata

Hi all,
I found that my testing server is accumulating shapshot folder in repldata.
Everytime, we refresh the tables (snapshot publication), a new folder created
without the old folders. And I found that there is at most 1 snapshot
folder remain in production server. Any parameter to adjust the retention
period of the snapshot folder? Thanks in advance
It is normal to create a date stamped snapshot folder within your main
publication snapshot folder, for example within here
C:\Program Files\Microsoft SQL
Server\MSSQL.2\MSSQL\repldata\unc\Publisher_P2P1_P 2P1
These are normally cleaned up by one of the clean up jobs.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"stephanie" <stephanie@.discussions.microsoft.com> wrote in message
news:24DD103F-DFB5-4331-B04C-B2E3E9ECBB12@.microsoft.com...
> Hi all,
> I found that my testing server is accumulating shapshot folder in
> repldata.
> Everytime, we refresh the tables (snapshot publication), a new folder
> created
> without the old folders. And I found that there is at most 1 snapshot
> folder remain in production server. Any parameter to adjust the retention
> period of the snapshot folder? Thanks in advance
|||This should remain until the distribution retention period is reached (named
subscriber not yet initialized or anonymous subscribers enabled) or all
subscribers have been initialized. After that the cleanup agent will delete
the folder.
Paul Ibison
|||I found the distribution transaction retention is 1-12 hrs only and there is
2 snapshot folders generated more than 1 weeks ago. Any idea? Thanks a lot.
"Paul Ibison" wrote:

> This should remain until the distribution retention period is reached (named
> subscriber not yet initialized or anonymous subscribers enabled) or all
> subscribers have been initialized. After that the cleanup agent will delete
> the folder.
> Paul Ibison

Saturday, February 25, 2012

Accidentally dropped DBO from database

I altered a script that drops all users from a database and accidentally
changes an AND to an OR so that the user DBO was dropped after a refresh fro
m
production to dev.
Can I readd this user or is the only solution is to restore from backup?
Thanks,
LindaYou can use sp_changedbowner and dbo will map to whatever
login you assign as the database owner with
sp_changedbonwer.
You can find more information on sp_changedbowner in SQL
Server books online.
-Sue
On Tue, 18 Jan 2005 06:25:03 -0800, "Linda"
<Linda@.discussions.microsoft.com> wrote:

>I altered a script that drops all users from a database and accidentally
>changes an AND to an OR so that the user DBO was dropped after a refresh fr
om
>production to dev.
>Can I readd this user or is the only solution is to restore from backup?
>Thanks,
>Linda|||The user dbo was dropped from sysusers. This did not solve the problem. I
ended up restoring the database from backup but that took several hours and
I
had been hoping a quick script to add dbo back to sysusers might solve it.
"Sue Hoegemeier" wrote:

> You can use sp_changedbowner and dbo will map to whatever
> login you assign as the database owner with
> sp_changedbonwer.
> You can find more information on sp_changedbowner in SQL
> Server books online.
> -Sue
> On Tue, 18 Jan 2005 06:25:03 -0800, "Linda"
> <Linda@.discussions.microsoft.com> wrote:
>
>|||Actually, what I suggested is exactly how you fix the issue.
Without any information on what happened or what errors you
had, it's hard to give you more specifics.
If you were receiving the error:
Error 21776: [SQL-DMO] The name 'dbo' was not found in the
Users collection. If the name is a qualified name, use [] to
separate the various parts of the name, and try again
That error is due to having databases where the owner (dbo)
is mapped to a login that doesn't exist on the server. It's
not a matter of DBO being dropped but rather problems with
the mappings.
If you get an error along the lines of "the user is already
a user in the database" when using sp_changedbowner, that's
generally due to a mismatch between dbo and the database
owner. You can work around this by creating a temp login,
change the owner to this new login, then change the owner to
the login you actually want to be the owner and drop the
temporary login.
-Sue
On Thu, 20 Jan 2005 08:57:06 -0800, "lslmustang"
<lslmustang@.discussions.microsoft.com> wrote:
[vbcol=seagreen]
>The user dbo was dropped from sysusers. This did not solve the problem. I
>ended up restoring the database from backup but that took several hours and
I
>had been hoping a quick script to add dbo back to sysusers might solve it.
>"Sue Hoegemeier" wrote:
>