Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Monday, March 26, 2012

LogSpace Script

I am writing a logspace checking script. For now I just
want it to send me the size of all my log files. But I
am doing something stupid or don't understand cursors
because it's only putting the last database into @.msg3.
If anyone has any ideas what I'm doing wrong, I'd sure
appreciate it as this is driving me crazy!
declare @.server varchar(50)
declare @.subject2 varchar(50)
declare @.msg2 varchar(8000)
declare @.msg3 varchar(8000)
declare @.email_body varchar(8000)
declare @.field1 varchar(100)
declare @.field2 varchar(100)
--declare testint int
set @.server = 'SQL_3'
set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
LOG SPACE OVER 2G'
print @.subject2
if exists (select name from tempdb..sysobjects where name
like '#temcmlogspace%')
begin
drop table #temcmlogspace
end
create table #temcmlogspace (dbname varchar(100) null,
logsize2 numeric(16, 6) null,
logusedpcnt numeric(16,6) null, status2 int null)
--The size is in Megs:
insert into #temcmlogspace
exec ('dbcc sqlperf(logspace)')
set @.msg3 = ''
declare email_cursor cursor for
select dbname, logsize2 from #temcmlogspace
open email_cursor
while @.@.fetch_status = 0
fetch next from email_cursor into @.field1, @.field2
begin
set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
(20))
set @.msg3 = @.msg3 + @.msg2
print '@.msg2'
print @.msg2
end
close email_cursor
deallocate email_cursor
print '@.msg3'
print @.msg3
Is it possible that @.field1 and/or @.field2 is ever NULL?
http://www.aspfaq.com/
(Reverse address to reply.)
"Alley" <anonymous@.discussions.microsoft.com> wrote in message
news:0c9901c4fe6b$3632a120$a601280a@.phx.gbl...
> I am writing a logspace checking script. For now I just
> want it to send me the size of all my log files. But I
> am doing something stupid or don't understand cursors
> because it's only putting the last database into @.msg3.
> If anyone has any ideas what I'm doing wrong, I'd sure
> appreciate it as this is driving me crazy!
>
> declare @.server varchar(50)
> declare @.subject2 varchar(50)
> declare @.msg2 varchar(8000)
> declare @.msg3 varchar(8000)
> declare @.email_body varchar(8000)
> declare @.field1 varchar(100)
> declare @.field2 varchar(100)
> --declare testint int
> set @.server = 'SQL_3'
> set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
> LOG SPACE OVER 2G'
> print @.subject2
> if exists (select name from tempdb..sysobjects where name
> like '#temcmlogspace%')
> begin
> drop table #temcmlogspace
> end
> create table #temcmlogspace (dbname varchar(100) null,
> logsize2 numeric(16, 6) null,
> logusedpcnt numeric(16,6) null, status2 int null)
> --The size is in Megs:
> insert into #temcmlogspace
> exec ('dbcc sqlperf(logspace)')
> set @.msg3 = ''
> declare email_cursor cursor for
> select dbname, logsize2 from #temcmlogspace
> open email_cursor
> while @.@.fetch_status = 0
> fetch next from email_cursor into @.field1, @.field2
> begin
> set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
> (20))
> set @.msg3 = @.msg3 + @.msg2
> print '@.msg2'
> print @.msg2
> end
> close email_cursor
> deallocate email_cursor
> print '@.msg3'
> print @.msg3
>
>
|||Shouldn't be: it's taking the results from DBCC
Logspace. Why?
>--Original Message--
>Is it possible that @.field1 and/or @.field2 is ever NULL?
>--
>http://www.aspfaq.com/
>(Reverse address to reply.)
>
>
>"Alley" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:0c9901c4fe6b$3632a120$a601280a@.phx.gbl...
just[vbcol=seagreen]
WITH[vbcol=seagreen]
name
>
>.
>
|||Well, if you set @.msg3 = @.msg3 + NULL, guess what happens?
http://www.aspfaq.com/
(Reverse address to reply.)
"Alley" <anonymous@.discussions.microsoft.com> wrote in message
news:1c6201c4fe6f$54022c30$a501280a@.phx.gbl...[vbcol=seagreen]
> Shouldn't be: it's taking the results from DBCC
> Logspace. Why?
> message
> just
> WITH
> name
|||Thx for the help, but I figured out what was wrong. I
had the incorrect order. This script works:
declare @.server varchar(50)
declare @.subject2 varchar(50)
declare @.msg2 varchar(8000)
declare @.msg3 varchar(8000)
declare @.email_body varchar(8000)
declare @.field1 varchar(100)
declare @.field2 numeric(16, 6)
--declare testint int
set @.server = 'SQL_3'
set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
LOG SPACE OVER 2G'
print @.subject2
if exists (select name from tempdb..sysobjects where name
like '#temcmlogspace%')
begin
drop table #temcmlogspace
end
create table #temcmlogspace (dbname varchar(100) null,
logsize2 numeric(16, 6) null,
logusedpcnt numeric(16,6) null, status2 int null)
--The size is in Megs:
insert into #temcmlogspace
exec ('dbcc sqlperf(logspace)')
--select * from #temcmlogspace
set @.msg3 = ''
declare email_cursor cursor for
select dbname, logsize2 from #temcmlogspace
open email_cursor
while @.@.fetch_status = 0
begin
fetch next from email_cursor into @.field1, @.field2
set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
(20))
set @.msg3 = @.msg3 + @.msg2
--print '@.msg2'
--print @.msg2
end
close email_cursor
deallocate email_cursor
--print '@.msg3'
--print @.msg3
>--Original Message--
>Well, if you set @.msg3 = @.msg3 + NULL, guess what
happens?
>--
>http://www.aspfaq.com/
>(Reverse address to reply.)
>
>
>"Alley" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:1c6201c4fe6f$54022c30$a501280a@.phx.gbl...
NULL?[vbcol=seagreen]
But I[vbcol=seagreen]
cursors[vbcol=seagreen]
@.msg3.[vbcol=seagreen]
sure[vbcol=seagreen]
null,[vbcol=seagreen]
varchar
>
>.
>

LogSpace Script

I am writing a logspace checking script. For now I just
want it to send me the size of all my log files. But I
am doing something stupid or don't understand cursors
because it's only putting the last database into @.msg3.
If anyone has any ideas what I'm doing wrong, I'd sure
appreciate it as this is driving me crazy!
declare @.server varchar(50)
declare @.subject2 varchar(50)
declare @.msg2 varchar(8000)
declare @.msg3 varchar(8000)
declare @.email_body varchar(8000)
declare @.field1 varchar(100)
declare @.field2 varchar(100)
--declare testint int
set @.server = 'SQL_3'
set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
LOG SPACE OVER 2G'
print @.subject2
if exists (select name from tempdb..sysobjects where name
like '#temcmlogspace%')
begin
drop table #temcmlogspace
end
create table #temcmlogspace (dbname varchar(100) null,
logsize2 numeric(16, 6) null,
logusedpcnt numeric(16,6) null, status2 int null)
--The size is in Megs:
insert into #temcmlogspace
exec ('dbcc sqlperf(logspace)')
set @.msg3 = ''
declare email_cursor cursor for
select dbname, logsize2 from #temcmlogspace
open email_cursor
while @.@.fetch_status = 0
fetch next from email_cursor into @.field1, @.field2
begin
set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
(20))
set @.msg3 = @.msg3 + @.msg2
print '@.msg2'
print @.msg2
end
close email_cursor
deallocate email_cursor
print '@.msg3'
print @.msg3Is it possible that @.field1 and/or @.field2 is ever NULL?
http://www.aspfaq.com/
(Reverse address to reply.)
"Alley" <anonymous@.discussions.microsoft.com> wrote in message
news:0c9901c4fe6b$3632a120$a601280a@.phx.gbl...
> I am writing a logspace checking script. For now I just
> want it to send me the size of all my log files. But I
> am doing something stupid or don't understand cursors
> because it's only putting the last database into @.msg3.
> If anyone has any ideas what I'm doing wrong, I'd sure
> appreciate it as this is driving me crazy!
>
> declare @.server varchar(50)
> declare @.subject2 varchar(50)
> declare @.msg2 varchar(8000)
> declare @.msg3 varchar(8000)
> declare @.email_body varchar(8000)
> declare @.field1 varchar(100)
> declare @.field2 varchar(100)
> --declare testint int
> set @.server = 'SQL_3'
> set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
> LOG SPACE OVER 2G'
> print @.subject2
> if exists (select name from tempdb..sysobjects where name
> like '#temcmlogspace%')
> begin
> drop table #temcmlogspace
> end
> create table #temcmlogspace (dbname varchar(100) null,
> logsize2 numeric(16, 6) null,
> logusedpcnt numeric(16,6) null, status2 int null)
> --The size is in Megs:
> insert into #temcmlogspace
> exec ('dbcc sqlperf(logspace)')
> set @.msg3 = ''
> declare email_cursor cursor for
> select dbname, logsize2 from #temcmlogspace
> open email_cursor
> while @.@.fetch_status = 0
> fetch next from email_cursor into @.field1, @.field2
> begin
> set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
> (20))
> set @.msg3 = @.msg3 + @.msg2
> print '@.msg2'
> print @.msg2
> end
> close email_cursor
> deallocate email_cursor
> print '@.msg3'
> print @.msg3
>
>|||Shouldn't be: it's taking the results from DBCC
Logspace. Why?
>--Original Message--
>Is it possible that @.field1 and/or @.field2 is ever NULL?
>--
>http://www.aspfaq.com/
>(Reverse address to reply.)
>
>
>"Alley" <anonymous@.discussions.microsoft.com> wrote in
message
>news:0c9901c4fe6b$3632a120$a601280a@.phx.gbl...
just[vbcol=seagreen]
WITH[vbcol=seagreen]
name[vbcol=seagreen]
>
>.
>|||Well, if you set @.msg3 = @.msg3 + NULL, guess what happens?
http://www.aspfaq.com/
(Reverse address to reply.)
"Alley" <anonymous@.discussions.microsoft.com> wrote in message
news:1c6201c4fe6f$54022c30$a501280a@.phx.gbl...[vbcol=seagreen]
> Shouldn't be: it's taking the results from DBCC
> Logspace. Why?
> message
> just
> WITH
> name|||Thx for the help, but I figured out what was wrong. I
had the incorrect order. This script works:
declare @.server varchar(50)
declare @.subject2 varchar(50)
declare @.msg2 varchar(8000)
declare @.msg3 varchar(8000)
declare @.email_body varchar(8000)
declare @.field1 varchar(100)
declare @.field2 numeric(16, 6)
--declare testint int
set @.server = 'SQL_3'
set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
LOG SPACE OVER 2G'
print @.subject2
if exists (select name from tempdb..sysobjects where name
like '#temcmlogspace%')
begin
drop table #temcmlogspace
end
create table #temcmlogspace (dbname varchar(100) null,
logsize2 numeric(16, 6) null,
logusedpcnt numeric(16,6) null, status2 int null)
--The size is in Megs:
insert into #temcmlogspace
exec ('dbcc sqlperf(logspace)')
--select * from #temcmlogspace
set @.msg3 = ''
declare email_cursor cursor for
select dbname, logsize2 from #temcmlogspace
open email_cursor
while @.@.fetch_status = 0
begin
fetch next from email_cursor into @.field1, @.field2
set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
(20))
set @.msg3 = @.msg3 + @.msg2
--print '@.msg2'
--print @.msg2
end
close email_cursor
deallocate email_cursor
--print '@.msg3'
--print @.msg3
>--Original Message--
>Well, if you set @.msg3 = @.msg3 + NULL, guess what
happens?
>--
>http://www.aspfaq.com/
>(Reverse address to reply.)
>
>
>"Alley" <anonymous@.discussions.microsoft.com> wrote in
message
>news:1c6201c4fe6f$54022c30$a501280a@.phx.gbl...
NULL?[vbcol=seagreen]
But I[vbcol=seagreen]
cursors[vbcol=seagreen]
@.msg3.[vbcol=seagreen]
sure[vbcol=seagreen]
null,[vbcol=seagreen]
varchar[vbcol=seagreen]
>
>.
>sql

LogSpace Script

I am writing a logspace checking script. For now I just
want it to send me the size of all my log files. But I
am doing something stupid or don't understand cursors
because it's only putting the last database into @.msg3.
If anyone has any ideas what I'm doing wrong, I'd sure
appreciate it as this is driving me crazy!
declare @.server varchar(50)
declare @.subject2 varchar(50)
declare @.msg2 varchar(8000)
declare @.msg3 varchar(8000)
declare @.email_body varchar(8000)
declare @.field1 varchar(100)
declare @.field2 varchar(100)
--declare testint int
set @.server = 'SQL_3'
set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
LOG SPACE OVER 2G'
print @.subject2
if exists (select name from tempdb..sysobjects where name
like '#temcmlogspace%')
begin
drop table #temcmlogspace
end
create table #temcmlogspace (dbname varchar(100) null,
logsize2 numeric(16, 6) null,
logusedpcnt numeric(16,6) null, status2 int null)
--The size is in Megs:
insert into #temcmlogspace
exec ('dbcc sqlperf(logspace)')
set @.msg3 = ''
declare email_cursor cursor for
select dbname, logsize2 from #temcmlogspace
open email_cursor
while @.@.fetch_status = 0
fetch next from email_cursor into @.field1, @.field2
begin
set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
(20))
set @.msg3 = @.msg3 + @.msg2
print '@.msg2'
print @.msg2
end
close email_cursor
deallocate email_cursor
print '@.msg3'
print @.msg3Is it possible that @.field1 and/or @.field2 is ever NULL?
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Alley" <anonymous@.discussions.microsoft.com> wrote in message
news:0c9901c4fe6b$3632a120$a601280a@.phx.gbl...
> I am writing a logspace checking script. For now I just
> want it to send me the size of all my log files. But I
> am doing something stupid or don't understand cursors
> because it's only putting the last database into @.msg3.
> If anyone has any ideas what I'm doing wrong, I'd sure
> appreciate it as this is driving me crazy!
>
> declare @.server varchar(50)
> declare @.subject2 varchar(50)
> declare @.msg2 varchar(8000)
> declare @.msg3 varchar(8000)
> declare @.email_body varchar(8000)
> declare @.field1 varchar(100)
> declare @.field2 varchar(100)
> --declare testint int
> set @.server = 'SQL_3'
> set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
> LOG SPACE OVER 2G'
> print @.subject2
> if exists (select name from tempdb..sysobjects where name
> like '#temcmlogspace%')
> begin
> drop table #temcmlogspace
> end
> create table #temcmlogspace (dbname varchar(100) null,
> logsize2 numeric(16, 6) null,
> logusedpcnt numeric(16,6) null, status2 int null)
> --The size is in Megs:
> insert into #temcmlogspace
> exec ('dbcc sqlperf(logspace)')
> set @.msg3 = ''
> declare email_cursor cursor for
> select dbname, logsize2 from #temcmlogspace
> open email_cursor
> while @.@.fetch_status = 0
> fetch next from email_cursor into @.field1, @.field2
> begin
> set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
> (20))
> set @.msg3 = @.msg3 + @.msg2
> print '@.msg2'
> print @.msg2
> end
> close email_cursor
> deallocate email_cursor
> print '@.msg3'
> print @.msg3
>
>|||Shouldn't be: it's taking the results from DBCC
Logspace. Why?
>--Original Message--
>Is it possible that @.field1 and/or @.field2 is ever NULL?
>--
>http://www.aspfaq.com/
>(Reverse address to reply.)
>
>
>"Alley" <anonymous@.discussions.microsoft.com> wrote in
message
>news:0c9901c4fe6b$3632a120$a601280a@.phx.gbl...
>> I am writing a logspace checking script. For now I
just
>> want it to send me the size of all my log files. But I
>> am doing something stupid or don't understand cursors
>> because it's only putting the last database into @.msg3.
>> If anyone has any ideas what I'm doing wrong, I'd sure
>> appreciate it as this is driving me crazy!
>>
>> declare @.server varchar(50)
>> declare @.subject2 varchar(50)
>> declare @.msg2 varchar(8000)
>> declare @.msg3 varchar(8000)
>> declare @.email_body varchar(8000)
>> declare @.field1 varchar(100)
>> declare @.field2 varchar(100)
>> --declare testint int
>> set @.server = 'SQL_3'
>> set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs
WITH
>> LOG SPACE OVER 2G'
>> print @.subject2
>> if exists (select name from tempdb..sysobjects where
name
>> like '#temcmlogspace%')
>> begin
>> drop table #temcmlogspace
>> end
>> create table #temcmlogspace (dbname varchar(100) null,
>> logsize2 numeric(16, 6) null,
>> logusedpcnt numeric(16,6) null, status2 int null)
>> --The size is in Megs:
>> insert into #temcmlogspace
>> exec ('dbcc sqlperf(logspace)')
>> set @.msg3 = ''
>> declare email_cursor cursor for
>> select dbname, logsize2 from #temcmlogspace
>> open email_cursor
>> while @.@.fetch_status = 0
>> fetch next from email_cursor into @.field1, @.field2
>> begin
>> set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
>> (20))
>> set @.msg3 = @.msg3 + @.msg2
>> print '@.msg2'
>> print @.msg2
>> end
>> close email_cursor
>> deallocate email_cursor
>> print '@.msg3'
>> print @.msg3
>>
>>
>
>.
>|||Well, if you set @.msg3 = @.msg3 + NULL, guess what happens?
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Alley" <anonymous@.discussions.microsoft.com> wrote in message
news:1c6201c4fe6f$54022c30$a501280a@.phx.gbl...
> Shouldn't be: it's taking the results from DBCC
> Logspace. Why?
> >--Original Message--
> >Is it possible that @.field1 and/or @.field2 is ever NULL?
> >
> >--
> >http://www.aspfaq.com/
> >(Reverse address to reply.)
> >
> >
> >
> >
> >"Alley" <anonymous@.discussions.microsoft.com> wrote in
> message
> >news:0c9901c4fe6b$3632a120$a601280a@.phx.gbl...
> >> I am writing a logspace checking script. For now I
> just
> >> want it to send me the size of all my log files. But I
> >> am doing something stupid or don't understand cursors
> >> because it's only putting the last database into @.msg3.
> >> If anyone has any ideas what I'm doing wrong, I'd sure
> >> appreciate it as this is driving me crazy!
> >>
> >>
> >> declare @.server varchar(50)
> >> declare @.subject2 varchar(50)
> >> declare @.msg2 varchar(8000)
> >> declare @.msg3 varchar(8000)
> >> declare @.email_body varchar(8000)
> >> declare @.field1 varchar(100)
> >> declare @.field2 varchar(100)
> >> --declare testint int
> >>
> >> set @.server = 'SQL_3'
> >> set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs
> WITH
> >> LOG SPACE OVER 2G'
> >> print @.subject2
> >> if exists (select name from tempdb..sysobjects where
> name
> >> like '#temcmlogspace%')
> >> begin
> >> drop table #temcmlogspace
> >> end
> >> create table #temcmlogspace (dbname varchar(100) null,
> >> logsize2 numeric(16, 6) null,
> >> logusedpcnt numeric(16,6) null, status2 int null)
> >> --The size is in Megs:
> >> insert into #temcmlogspace
> >> exec ('dbcc sqlperf(logspace)')
> >> set @.msg3 = ''
> >> declare email_cursor cursor for
> >> select dbname, logsize2 from #temcmlogspace
> >> open email_cursor
> >>
> >> while @.@.fetch_status = 0
> >> fetch next from email_cursor into @.field1, @.field2
> >> begin
> >> set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
> >> (20))
> >> set @.msg3 = @.msg3 + @.msg2
> >> print '@.msg2'
> >> print @.msg2
> >> end
> >> close email_cursor
> >> deallocate email_cursor
> >> print '@.msg3'
> >> print @.msg3
> >>
> >>
> >>
> >>
> >
> >
> >.
> >|||Thx for the help, but I figured out what was wrong. I
had the incorrect order. This script works:
declare @.server varchar(50)
declare @.subject2 varchar(50)
declare @.msg2 varchar(8000)
declare @.msg3 varchar(8000)
declare @.email_body varchar(8000)
declare @.field1 varchar(100)
declare @.field2 numeric(16, 6)
--declare testint int
set @.server = 'SQL_3'
set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs WITH
LOG SPACE OVER 2G'
print @.subject2
if exists (select name from tempdb..sysobjects where name
like '#temcmlogspace%')
begin
drop table #temcmlogspace
end
create table #temcmlogspace (dbname varchar(100) null,
logsize2 numeric(16, 6) null,
logusedpcnt numeric(16,6) null, status2 int null)
--The size is in Megs:
insert into #temcmlogspace
exec ('dbcc sqlperf(logspace)')
--select * from #temcmlogspace
set @.msg3 = ''
declare email_cursor cursor for
select dbname, logsize2 from #temcmlogspace
open email_cursor
while @.@.fetch_status = 0
begin
fetch next from email_cursor into @.field1, @.field2
set @.msg2 = @.field1 + ' ' + cast(@.field2 as varchar
(20))
set @.msg3 = @.msg3 + @.msg2
--print '@.msg2'
--print @.msg2
end
close email_cursor
deallocate email_cursor
--print '@.msg3'
--print @.msg3
>--Original Message--
>Well, if you set @.msg3 = @.msg3 + NULL, guess what
happens?
>--
>http://www.aspfaq.com/
>(Reverse address to reply.)
>
>
>"Alley" <anonymous@.discussions.microsoft.com> wrote in
message
>news:1c6201c4fe6f$54022c30$a501280a@.phx.gbl...
>> Shouldn't be: it's taking the results from DBCC
>> Logspace. Why?
>> >--Original Message--
>> >Is it possible that @.field1 and/or @.field2 is ever
NULL?
>> >
>> >--
>> >http://www.aspfaq.com/
>> >(Reverse address to reply.)
>> >
>> >
>> >
>> >
>> >"Alley" <anonymous@.discussions.microsoft.com> wrote in
>> message
>> >news:0c9901c4fe6b$3632a120$a601280a@.phx.gbl...
>> >> I am writing a logspace checking script. For now I
>> just
>> >> want it to send me the size of all my log files.
But I
>> >> am doing something stupid or don't understand
cursors
>> >> because it's only putting the last database into
@.msg3.
>> >> If anyone has any ideas what I'm doing wrong, I'd
sure
>> >> appreciate it as this is driving me crazy!
>> >>
>> >>
>> >> declare @.server varchar(50)
>> >> declare @.subject2 varchar(50)
>> >> declare @.msg2 varchar(8000)
>> >> declare @.msg3 varchar(8000)
>> >> declare @.email_body varchar(8000)
>> >> declare @.field1 varchar(100)
>> >> declare @.field2 varchar(100)
>> >> --declare testint int
>> >>
>> >> set @.server = 'SQL_3'
>> >> set @.subject2 = 'LOGSPACE ON ' + @.server + ' FOR DBs
>> WITH
>> >> LOG SPACE OVER 2G'
>> >> print @.subject2
>> >> if exists (select name from tempdb..sysobjects where
>> name
>> >> like '#temcmlogspace%')
>> >> begin
>> >> drop table #temcmlogspace
>> >> end
>> >> create table #temcmlogspace (dbname varchar(100)
null,
>> >> logsize2 numeric(16, 6) null,
>> >> logusedpcnt numeric(16,6) null, status2 int null)
>> >> --The size is in Megs:
>> >> insert into #temcmlogspace
>> >> exec ('dbcc sqlperf(logspace)')
>> >> set @.msg3 = ''
>> >> declare email_cursor cursor for
>> >> select dbname, logsize2 from #temcmlogspace
>> >> open email_cursor
>> >>
>> >> while @.@.fetch_status = 0
>> >> fetch next from email_cursor into @.field1, @.field2
>> >> begin
>> >> set @.msg2 = @.field1 + ' ' + cast(@.field2 as
varchar
>> >> (20))
>> >> set @.msg3 = @.msg3 + @.msg2
>> >> print '@.msg2'
>> >> print @.msg2
>> >> end
>> >> close email_cursor
>> >> deallocate email_cursor
>> >> print '@.msg3'
>> >> print @.msg3
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>> >.
>> >
>
>.
>

Monday, March 19, 2012

Logon failed. (rsLogonFailed)

Hi,
I am writing a web application in c# that is attempting to get the
parameters from a report on a Reporting Services 2005 server.
I am using the following code:
SQLReportViewer.ServerReport.ReportServerCredentials = new
ReportCredentials(UserName, UserPassword, UserDomain);
SQLReportViewer.ServerReport.ReportPath = Rpt.FileName;
SQLReportViewer.ServerReport.ReportServerUrl = new Uri(ServerUrl);
Parameters = SQLReportViewer.ServerReport.GetParameters();
The Getparameters Line causes the following exception:
Microsoft.Reporting.WebForms.ReportServerException was unhandled by user
code
Message="Logon failed. (rsLogonFailed)"
Source="Microsoft.ReportViewer.WebForms"
ErrorCode="rsLogonFailed"
StackTrace:
at Microsoft.Reporting.WebForms.ServerReport.get_Service()
at Microsoft.Reporting.WebForms.ServerReport.GetExecutionInfo()
at Microsoft.Reporting.WebForms.ServerReport.GetParameters()
The UserName, UserPassword and UserDomain variables are all populated
with correct data, as is Rpt.FileName.
The ReportCredentials class is a very simple implementation of the
ICredentials interface - Code shown here:
-->
public class ReportCredentials : IReportServerCredentials
{
protected string _UserName, _Password, _Domain;
public ReportCredentials(string UserName, string Password, string Domain)
{
_UserName = UserName;
_Password = Password;
_Domain = Domain;
}
//*****************************************************************
public bool GetFormsCredentials (out System.Net.Cookie AuthCookie,
out string UserName, out string Password, out string Authority)
{
UserName = _UserName;
Password = _Password;
Authority = _Domain;
AuthCookie = null;
return (true);
}
//*****************************************************************
public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get { return (null); }
}
//*****************************************************************
public ICredentials NetworkCredentials
{
get{ return (new NetworkCredential(_UserName, _Password, _Domain)); }
}
<--
I can use the same credentials to retrieve a list of reports from the
report server (the report I am trying to access is in that list) and to
log on directly by going to the URL of Reporting Services.
This is made more frustrating by the complete lack of detail in the
error message, as it does not say why the logon failed, or give me a
single clue about what is going on.
Has anyone seen this before and can tell me how to fix it, or is there
something stupid in my code?
Thankyou.
PaulTwo points. What role is your user in? It could be that perhaps you need to
be in a different role to get information about the report than you do to
get a list of reports? It seems to me if it worked for a list of reports
then your login must be OK.
Second issue. For something like this I recommend trying to web forum. The
other MVP is there and is familiar with webservices. Also, that is where MS
people hang out.
http://forums.microsoft.com/msdn/showforum.aspx?forumid=82&siteid=1
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Paul Cheetham" <PAC.News@.dsl.pipex.com> wrote in message
news:%231p4s096HHA.5164@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I am writing a web application in c# that is attempting to get the
> parameters from a report on a Reporting Services 2005 server.
> I am using the following code:
> SQLReportViewer.ServerReport.ReportServerCredentials = new
> ReportCredentials(UserName, UserPassword, UserDomain);
> SQLReportViewer.ServerReport.ReportPath = Rpt.FileName;
> SQLReportViewer.ServerReport.ReportServerUrl = new Uri(ServerUrl);
> Parameters = SQLReportViewer.ServerReport.GetParameters();
> The Getparameters Line causes the following exception:
>
> Microsoft.Reporting.WebForms.ReportServerException was unhandled by user
> code
> Message="Logon failed. (rsLogonFailed)"
> Source="Microsoft.ReportViewer.WebForms"
> ErrorCode="rsLogonFailed"
> StackTrace:
> at Microsoft.Reporting.WebForms.ServerReport.get_Service()
> at Microsoft.Reporting.WebForms.ServerReport.GetExecutionInfo()
> at Microsoft.Reporting.WebForms.ServerReport.GetParameters()
>
> The UserName, UserPassword and UserDomain variables are all populated with
> correct data, as is Rpt.FileName.
> The ReportCredentials class is a very simple implementation of the
> ICredentials interface - Code shown here:
>
> -->
> public class ReportCredentials : IReportServerCredentials
> {
> protected string _UserName, _Password, _Domain;
> public ReportCredentials(string UserName, string Password, string Domain)
> {
> _UserName = UserName;
> _Password = Password;
> _Domain = Domain;
> }
> //*****************************************************************
> public bool GetFormsCredentials (out System.Net.Cookie AuthCookie, out
> string UserName, out string Password, out string Authority)
> {
> UserName = _UserName;
> Password = _Password;
> Authority = _Domain;
> AuthCookie = null;
> return (true);
> }
> //*****************************************************************
> public System.Security.Principal.WindowsIdentity ImpersonationUser
> {
> get { return (null); }
> }
> //*****************************************************************
> public ICredentials NetworkCredentials
> {
> get{ return (new NetworkCredential(_UserName, _Password, _Domain)); }
> }
> <--
> I can use the same credentials to retrieve a list of reports from the
> report server (the report I am trying to access is in that list) and to
> log on directly by going to the URL of Reporting Services.
> This is made more frustrating by the complete lack of detail in the error
> message, as it does not say why the logon failed, or give me a single clue
> about what is going on.
> Has anyone seen this before and can tell me how to fix it, or is there
> something stupid in my code?
> Thankyou.
> Paul
>|||OK Thanks, I'll post there.
I'm pretty sure the Role is OK, as I know the same user details are
being used successfully in another application, which I am replacing,
but that is just showing the report and is not trying to get the
Parameter list.
Paul
Bruce L-C [MVP] wrote:
> Two points. What role is your user in? It could be that perhaps you need to
> be in a different role to get information about the report than you do to
> get a list of reports? It seems to me if it worked for a list of reports
> then your login must be OK.
> Second issue. For something like this I recommend trying to web forum. The
> other MVP is there and is familiar with webservices. Also, that is where MS
> people hang out.
> http://forums.microsoft.com/msdn/showforum.aspx?forumid=82&siteid=1
>

Logon failed. (rsLogonFailed)

Hi,

I am writing a web application in c# that is attempting to get the parameters from a report on a Reporting Services 2005 server.

I am using the following code:

SQLReportViewer.ServerReport.ReportServerCredentials = new
ReportCredentials(UserName, UserPassword, UserDomain);
SQLReportViewer.ServerReport.ReportPath = Rpt.FileName;
SQLReportViewer.ServerReport.ReportServerUrl = new Uri(ServerUrl);

Parameters = SQLReportViewer.ServerReport.GetParameters();

The Getparameters Line causes the following exception:

Microsoft.Reporting.WebForms.ReportServerException was unhandled by user code
Message="Logon failed. (rsLogonFailed)"
Source="Microsoft.ReportViewer.WebForms"
ErrorCode="rsLogonFailed"
StackTrace:
at Microsoft.Reporting.WebForms.ServerReport.get_Service()
at Microsoft.Reporting.WebForms.ServerReport.GetExecutionInfo()
at Microsoft.Reporting.WebForms.ServerReport.GetParameters()

The UserName, UserPassword and UserDomain variables are all populated with correct data, as is Rpt.FileName.
The ReportCredentials class is a very simple implementation of the ICredentials interface - Code shown here:

-->

public class ReportCredentials : IReportServerCredentials
{
protected string _UserName, _Password, _Domain;

public ReportCredentials(string UserName, string Password, string Domain)
{
_UserName = UserName;
_Password = Password;
_Domain = Domain;
}

//*****************************************************************

public bool GetFormsCredentials (out System.Net.Cookie AuthCookie, out string UserName, out string Password, out string Authority)
{
UserName = _UserName;
Password = _Password;
Authority = _Domain;
AuthCookie = null;
return (true);
}

//*****************************************************************

public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get { return (null); }
}

//*****************************************************************

public ICredentials NetworkCredentials
{
get{ return (new NetworkCredential(_UserName, _Password, _Domain)); }
}

<--

I can use the same credentials to retrieve a list of reports from the report server (the report I am trying to access is in that list) and to log on directly by going to the URL of Reporting Services.

This is made more frustrating by the complete lack of detail in the error message, as it does not say why the logon failed, or give me a single clue about what is going on.

Has anyone seen this before and can tell me how to fix it, or is there something stupid in my code?

Thankyou.

Paul

Does the same thing happen when you do this:

Code Snippet

CredentialCache cc = new CredentialCache();

cc.Add(new Uri(Settings.Default.ReportServerEndPoint),"Basic", new NetworkCredential("uid", "pwd"));

reportViewer.ServerReport.ReportServerCredentials.NetworkCredentials = cc;

|||Hi,

ReportServerCredentials.NetworkCredentials is read only, and so cannot be assigned to.

Thankyou.

|||

You are right of course. Unline the WinForms version, the ASP.NET version of ReportViewer has NetworkCredentials read-only. Upon a second look, I don't see your code implementing IReportServerCredentials.GetBasicCredentials.

Code Snippet

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Reporting.WinForms;
using System.Security.Principal;


public class ReportViewerCredentials : IReportServerCredentials
{

public ReportViewerCredentials()
{
}

public ReportViewerCredentials(string username)
{
this.Username = username;
}


public ReportViewerCredentials(string username, string password)
{
this.Username = username;
this.Password = password;
}


public ReportViewerCredentials(string username, string password, string domain)
{
this.Username = username;
this.Password = password;
this.Domain = domain;
}


public string Username
{
get
{
return this.username;
}
set
{
string username = value;
if (username.Contains("\\"))
{
this.domain = username.Substring(0, username.IndexOf("\\"));
this.username = username.Substring(username.IndexOf("\\") + 1);
}
else
{
this.username = username;
}
}
}
private string username;

public string Password
{
get
{
return this.password;
}
set
{
this.password = value;
}
}
private string password;


public string Domain
{
get
{
return this.domain;
}
set
{
this.domain = value;
}
}
private string domain;


#region IReportServerCredentials Members

public bool GetBasicCredentials(out string basicUser, out string basicPassword, out string basicDomain)
{
basicUser = username;
basicPassword = password;
basicDomain = domain;
return username != null && password != null && domain != null;
}

public bool GetFormsCredentials(out string formsUser, out string formsPassword, out string formsAuthority)
{
formsUser = username;
formsPassword = password;
formsAuthority = domain;
return username != null && password != null && domain != null;

}

public WindowsIdentity ImpersonationUser
{
get
{
return null;
}
}

#endregion
}

|||Hi,

After much messing about and testing, I finally tracked it down to a problem in the GetformsCredentials function in my Credentials class.

By changing it to the following, everything works.

public bool GetFormsCredentials (out System.Net.Cookie AuthCookie, out string UserName, out string Password, out string Authority)
{
UserName = null;
Password = null;
Authority = null;
AuthCookie = null;

return (false);
}

Thanks

Paul

Logon failed. (rsLogonFailed)

Hi,

I am writing a web application in c# that is attempting to get the parameters from a report on a Reporting Services 2005 server.

I am using the following code:

SQLReportViewer.ServerReport.ReportServerCredentials = new
ReportCredentials(UserName, UserPassword, UserDomain);
SQLReportViewer.ServerReport.ReportPath = Rpt.FileName;
SQLReportViewer.ServerReport.ReportServerUrl = new Uri(ServerUrl);

Parameters = SQLReportViewer.ServerReport.GetParameters();

The Getparameters Line causes the following exception:

Microsoft.Reporting.WebForms.ReportServerException was unhandled by user code
Message="Logon failed. (rsLogonFailed)"
Source="Microsoft.ReportViewer.WebForms"
ErrorCode="rsLogonFailed"
StackTrace:
at Microsoft.Reporting.WebForms.ServerReport.get_Service()
at Microsoft.Reporting.WebForms.ServerReport.GetExecutionInfo()
at Microsoft.Reporting.WebForms.ServerReport.GetParameters()

The UserName, UserPassword and UserDomain variables are all populated with correct data, as is Rpt.FileName.
The ReportCredentials class is a very simple implementation of the ICredentials interface - Code shown here:

-->

public class ReportCredentials : IReportServerCredentials
{
protected string _UserName, _Password, _Domain;

public ReportCredentials(string UserName, string Password, string Domain)
{
_UserName = UserName;
_Password = Password;
_Domain = Domain;
}

//*****************************************************************

public bool GetFormsCredentials (out System.Net.Cookie AuthCookie, out string UserName, out string Password, out string Authority)
{
UserName = _UserName;
Password = _Password;
Authority = _Domain;
AuthCookie = null;
return (true);
}

//*****************************************************************

public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get { return (null); }
}

//*****************************************************************

public ICredentials NetworkCredentials
{
get{ return (new NetworkCredential(_UserName, _Password, _Domain)); }
}

<--

I can use the same credentials to retrieve a list of reports from the report server (the report I am trying to access is in that list) and to log on directly by going to the URL of Reporting Services.

This is made more frustrating by the complete lack of detail in the error message, as it does not say why the logon failed, or give me a single clue about what is going on.

Has anyone seen this before and can tell me how to fix it, or is there something stupid in my code?

Thankyou.

Paul

Does the same thing happen when you do this:

Code Snippet

CredentialCache cc = new CredentialCache();

cc.Add(new Uri(Settings.Default.ReportServerEndPoint),"Basic", new NetworkCredential("uid", "pwd"));

reportViewer.ServerReport.ReportServerCredentials.NetworkCredentials = cc;

|||Hi,

ReportServerCredentials.NetworkCredentials is read only, and so cannot be assigned to.

Thankyou.

|||

You are right of course. Unline the WinForms version, the ASP.NET version of ReportViewer has NetworkCredentials read-only. Upon a second look, I don't see your code implementing IReportServerCredentials.GetBasicCredentials.

Code Snippet

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Reporting.WinForms;
using System.Security.Principal;


public class ReportViewerCredentials : IReportServerCredentials
{

public ReportViewerCredentials()
{
}

public ReportViewerCredentials(string username)
{
this.Username = username;
}


public ReportViewerCredentials(string username, string password)
{
this.Username = username;
this.Password = password;
}


public ReportViewerCredentials(string username, string password, string domain)
{
this.Username = username;
this.Password = password;
this.Domain = domain;
}


public string Username
{
get
{
return this.username;
}
set
{
string username = value;
if (username.Contains("\\"))
{
this.domain = username.Substring(0, username.IndexOf("\\"));
this.username = username.Substring(username.IndexOf("\\") + 1);
}
else
{
this.username = username;
}
}
}
private string username;

public string Password
{
get
{
return this.password;
}
set
{
this.password = value;
}
}
private string password;


public string Domain
{
get
{
return this.domain;
}
set
{
this.domain = value;
}
}
private string domain;


#region IReportServerCredentials Members

public bool GetBasicCredentials(out string basicUser, out string basicPassword, out string basicDomain)
{
basicUser = username;
basicPassword = password;
basicDomain = domain;
return username != null && password != null && domain != null;
}

public bool GetFormsCredentials(out string formsUser, out string formsPassword, out string formsAuthority)
{
formsUser = username;
formsPassword = password;
formsAuthority = domain;
return username != null && password != null && domain != null;

}

public WindowsIdentity ImpersonationUser
{
get
{
return null;
}
}

#endregion
}

|||Hi,

After much messing about and testing, I finally tracked it down to a problem in the GetformsCredentials function in my Credentials class.

By changing it to the following, everything works.

public bool GetFormsCredentials (out System.Net.Cookie AuthCookie, out string UserName, out string Password, out string Authority)
{
UserName = null;
Password = null;
Authority = null;
AuthCookie = null;

return (false);
}

Thanks

Paul

Monday, March 12, 2012

Logins without User Mapping

Hi All
In SQL Server 2005 how do I go about writing a script to determine all
server logins that do not have any User Mapping?
As I have a test server where logins have been created and as databases have
been dropped there are now logins that exist that no longer have access to
any databases and I would like to remove them.
Thanks
Hello,
Take a loook into sp_change_users_logins system proc in books online..
Thanks
Hari
"David" <David@.discussions.microsoft.com> wrote in message
news:67EDE855-7967-4458-8526-1A80E4939578@.microsoft.com...
> Hi All
> In SQL Server 2005 how do I go about writing a script to determine all
> server logins that do not have any User Mapping?
> As I have a test server where logins have been created and as databases
> have
> been dropped there are now logins that exist that no longer have access to
> any databases and I would like to remove them.
> Thanks
|||Hi David
One way to do it is trying to run the query against the syslogins table in
the master database. An example of the query:
SELECT * FROM master.dbo.syslogins WHERE dbname IS NULL.
or try this one:
SELECT *
FROM master.dbo.syslogins
WHERE [sid] NOT IN (SELECT [sid] FROM database1.dbo.sysusers WHERE [sid] IS
NOT NULL)
AND [sid] NOT IN (SELECT [sid] FROM database2.dbo.sysusers WHERE [sid] IS
NOT NULL)
AND dbname <> 'master'
However, you might want to review the result first before deleting them. I
have not really tested the script in details. But logically it should work.
Hopes that's helpful.
Thank you
Lucas
"David" <David@.discussions.microsoft.com> wrote in message
news:67EDE855-7967-4458-8526-1A80E4939578@.microsoft.com...
> Hi All
> In SQL Server 2005 how do I go about writing a script to determine all
> server logins that do not have any User Mapping?
> As I have a test server where logins have been created and as databases
> have
> been dropped there are now logins that exist that no longer have access to
> any databases and I would like to remove them.
> Thanks

Logins without User Mapping

Hi All
In SQL Server 2005 how do I go about writing a script to determine all
server logins that do not have any User Mapping?
As I have a test server where logins have been created and as databases have
been dropped there are now logins that exist that no longer have access to
any databases and I would like to remove them.
ThanksHello,
Take a loook into sp_change_users_logins system proc in books online..
Thanks
Hari
"David" <David@.discussions.microsoft.com> wrote in message
news:67EDE855-7967-4458-8526-1A80E4939578@.microsoft.com...
> Hi All
> In SQL Server 2005 how do I go about writing a script to determine all
> server logins that do not have any User Mapping?
> As I have a test server where logins have been created and as databases
> have
> been dropped there are now logins that exist that no longer have access to
> any databases and I would like to remove them.
> Thanks|||Hi David
One way to do it is trying to run the query against the syslogins table in
the master database. An example of the query:
SELECT * FROM master.dbo.syslogins WHERE dbname IS NULL.
or try this one:
SELECT *
FROM master.dbo.syslogins
WHERE [sid] NOT IN (SELECT [sid] FROM database1.dbo.sysusers WHERE [sid] IS
NOT NULL)
AND [sid] NOT IN (SELECT [sid] FROM database2.dbo.sysusers WHERE [sid] IS
NOT NULL)
AND dbname <> 'master'
However, you might want to review the result first before deleting them. I
have not really tested the script in details. But logically it should work.
Hopes that's helpful.
Thank you
Lucas
"David" <David@.discussions.microsoft.com> wrote in message
news:67EDE855-7967-4458-8526-1A80E4939578@.microsoft.com...
> Hi All
> In SQL Server 2005 how do I go about writing a script to determine all
> server logins that do not have any User Mapping?
> As I have a test server where logins have been created and as databases
> have
> been dropped there are now logins that exist that no longer have access to
> any databases and I would like to remove them.
> Thanks

Logins without User Mapping

Hi All
In SQL Server 2005 how do I go about writing a script to determine all
server logins that do not have any User Mapping?
As I have a test server where logins have been created and as databases have
been dropped there are now logins that exist that no longer have access to
any databases and I would like to remove them.
ThanksHello,
Take a loook into sp_change_users_logins system proc in books online..
Thanks
Hari
"David" <David@.discussions.microsoft.com> wrote in message
news:67EDE855-7967-4458-8526-1A80E4939578@.microsoft.com...
> Hi All
> In SQL Server 2005 how do I go about writing a script to determine all
> server logins that do not have any User Mapping?
> As I have a test server where logins have been created and as databases
> have
> been dropped there are now logins that exist that no longer have access to
> any databases and I would like to remove them.
> Thanks|||Hi David
One way to do it is trying to run the query against the syslogins table in
the master database. An example of the query:
SELECT * FROM master.dbo.syslogins WHERE dbname IS NULL.
or try this one:
SELECT *
FROM master.dbo.syslogins
WHERE [sid] NOT IN (SELECT [sid] FROM database1.dbo.sysusers WHERE &
#91;sid] IS
NOT NULL)
AND [sid] NOT IN (SELECT [sid] FROM database2.dbo.sysusers WHERE
1;sid] IS
NOT NULL)
AND dbname <> 'master'
However, you might want to review the result first before deleting them. I
have not really tested the script in details. But logically it should work.
Hopes that's helpful.
Thank you
Lucas
"David" <David@.discussions.microsoft.com> wrote in message
news:67EDE855-7967-4458-8526-1A80E4939578@.microsoft.com...
> Hi All
> In SQL Server 2005 how do I go about writing a script to determine all
> server logins that do not have any User Mapping?
> As I have a test server where logins have been created and as databases
> have
> been dropped there are now logins that exist that no longer have access to
> any databases and I would like to remove them.
> Thanks

Friday, February 24, 2012

login problem with new project

I have several reports in a project that I deploy to a debug/development
environment and to production. I'm writing some different kinds of reports
so I created a new project. I've created different folders for these new
reports to go to. I updated the project configuration to point debug and
prod to the same servers but to different folders. The authentication is the
same. I use a SQL Server ID and PW stored within the report. I am admin on
both dev and prod servers.
When I try to deploy the new project reports to either environment, I get
the Reporting Services Login prompt, which I don't remember getting before.
I entered my domain user ID and PW but that did not work. I can still deploy
my old project reports with no issues. I must just be missing some sort of
project set-up step. Any ideas?
StephanieI solved it. I was using ...Reports instead of ...ReportServer in the
configuration.
Stephanie
"Stephanie" wrote:
> I have several reports in a project that I deploy to a debug/development
> environment and to production. I'm writing some different kinds of reports
> so I created a new project. I've created different folders for these new
> reports to go to. I updated the project configuration to point debug and
> prod to the same servers but to different folders. The authentication is the
> same. I use a SQL Server ID and PW stored within the report. I am admin on
> both dev and prod servers.
> When I try to deploy the new project reports to either environment, I get
> the Reporting Services Login prompt, which I don't remember getting before.
> I entered my domain user ID and PW but that did not work. I can still deploy
> my old project reports with no issues. I must just be missing some sort of
> project set-up step. Any ideas?
> Stephanie