Showing posts with label dbo. Show all posts
Showing posts with label dbo. Show all posts

Tuesday, March 20, 2012

Can't see stored proc results

I have this stored proc:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[usp_CrimRecTest]
-- Add the parameters for the stored procedure here
@.caseID [nvarchar]

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT dbo.tblCASENOMASTER.CASENO, dbo.tblCASEMAST.LASTNAME, dbo.tblCASEMAST.FRSTNAME
FROM dbo.tblCASENOMASTER LEFT OUTER JOIN
dbo.tblCASEMAST ON dbo.tblCASENOMASTER.CASENO = dbo.tblCASEMAST.CASENO
WHERE (dbo.tblCASENOMASTER.CASENO = @.caseID)
END

When I run this with an EXEC statement, the result pane shows no results but the message pane says it completed successfully and one row is affected. I know my input data is good. I also get nothing when I call this sproc from a VB front end. Any ideas?

Thanks.

What did you mean by --Insert statements for procedure here ? Is there something which you commented out for posting here ? The insert can prdouce x rows affected also as the Select part can. So the insert suceeded with X rows, but the query didn′t bring back any results.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de
|||All comment lines in this post are from the template produced when I created the sproc in SQL Server 2005. The code posted is copied directly from my sproc - nothing deleted, altered or commented out.|||

I found the problem.

@.caseID [nvarchar] was changed to:

@.caseID nvarchar(12)

This ran correctly.

Thanks for your reply Jens.

Monday, March 19, 2012

Cant save my stored procedure using VS2005

Hi!

I'm using VS2005 and trying to save my very simple stored procedure.
The error message "Invalid object name 'dbo.xxxxx' just pop's up.

The SP is written through the Server Explorer > Stored Procedures > Add new... etc.
Using SQL server 2000.

Don't think this has to do with the SP-code but here it is:

ALTER PROCEDUREdbo.KontrollUnikPersNr
@.PersNrnvarchar(50) =null OUTPUT
AS
SELECT@.PersNr = PersNrFROMUserWHEREPersNr = @.PersNr
RETURN@.@.ROWCOUNT

Thanx i advance for any help!

Looks like you are trying to ALTER a proc that does not exist. Try changing the ALTER to CREATE and see if it helps.

Also, I dont understand what you are trying to return from the stored proc - the rowcount or the value from the database?

|||

Thanx a lot!

I changed the Alter to Create and it works... didn't have to think of the in VS2003.

I'm returning the rowcount to see if there is any Users with the specific values that has to be unique in my user database table.

Thanks a lot again!Smile

|||

If you just need the count you could do it like this:

ALTER PROCEDURE dbo.KontrollUnikPersNr@.PersNrvarchar(50) =NULL,@.countint OUTPUTASBEGINSET NOCOUNT ONSELECT @.count =count(*)FROMUserWHERE PersNr = @.PersNrSET NOCOUNT OFFEND

|||

Hm, did'nt think of that... nice.

Thanx a lot again... let me know if I can help you with any tricky stuff.. erhm... Wink

Sunday, March 11, 2012

Can't run my scheduled job which accesses a linked server: other options?

I have a stored procedure in a database on a server, and this stored
procedure uses a linked server.
The login I was given is only granted DBO permissions on this database.
I am trying to set this up so that the above stored procedure runs once
per month, so I naturally tried to set up a Job which would do this.
I have discovered from another group that:
"You cannot access a linked server from a TSQL jobstep if you aren't
symin."
So: How can I automatically run this stored procedure once per month
under these conditions?
Thanks,
RyanIn SQL 2000, change the job owner to symin.
In SQL 2005, change the job security context.
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
<ryan_willow@.hotmail.com> wrote in message
news:1151015746.073933.305090@.r2g2000cwb.googlegroups.com...
>I have a stored procedure in a database on a server, and this stored
> procedure uses a linked server.
> The login I was given is only granted DBO permissions on this database.
> I am trying to set this up so that the above stored procedure runs once
> per month, so I naturally tried to set up a Job which would do this.
> I have discovered from another group that:
> "You cannot access a linked server from a TSQL jobstep if you aren't
> symin."
> So: How can I automatically run this stored procedure once per month
> under these conditions?
> Thanks,
> Ryan
>|||I'm in SQL 2000.
I cannot change the job owner because my permissions do not allow this.
Apparently a dbo user named 'User' can only create a job with owner
'User'. I am trying to implement this without having to step outside
my dbo security level. Is this going to be possible, and if so how?
Thanks.
Arnie Rowland wrote:
> In SQL 2000, change the job owner to symin.
> In SQL 2005, change the job security context.
> --
> Arnie Rowland, YACE*
> "To be successful, your heart must accompany your knowledge."
> *Yet Another certification Exam
>
> <ryan_willow@.hotmail.com> wrote in message
> news:1151015746.073933.305090@.r2g2000cwb.googlegroups.com...|||That will not be possible without coordination with the server
administrator. Since Jobs have the potential for significant performance
issues as well as security issues for the server, the security context for
Jobs is symin. (in SQL2000).
And of course a SQL Server Administrator is probably not going to allow you
to have permission to create or change a job because of the potential that
it could execute any code or activity under the symin security context.
Jobs are a 'Server' level activity -NOT a database level activity. Even if a
job is confined to a single database, it still operates as a server level
activity.
That changes with SQL 2005.
--
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another certification Exam
"Ryan" <ryan_willow@.hotmail.com> wrote in message
news:1151017863.128715.208750@.g10g2000cwb.googlegroups.com...
> I'm in SQL 2000.
> I cannot change the job owner because my permissions do not allow this.
> Apparently a dbo user named 'User' can only create a job with owner
> 'User'. I am trying to implement this without having to step outside
> my dbo security level. Is this going to be possible, and if so how?
> Thanks.
> Arnie Rowland wrote:
>|||Very informative, thanks Arnie.
Arnie Rowland wrote:
> That will not be possible without coordination with the server
> administrator. Since Jobs have the potential for significant performance
> issues as well as security issues for the server, the security context for
> Jobs is symin. (in SQL2000).
> And of course a SQL Server Administrator is probably not going to allow yo
u
> to have permission to create or change a job because of the potential that
> it could execute any code or activity under the symin security context.
> Jobs are a 'Server' level activity -NOT a database level activity. Even if
a
> job is confined to a single database, it still operates as a server level
> activity.
> That changes with SQL 2005.
> --
> Arnie Rowland, YACE*
> "To be successful, your heart must accompany your knowledge."
> *Yet Another certification Exam
>
> "Ryan" <ryan_willow@.hotmail.com> wrote in message
> news:1151017863.128715.208750@.g10g2000cwb.googlegroups.com...

Can't run my scheduled job which accesses a linked server: other options?

I have a stored procedure in a database on a server, and this stored
procedure uses a linked server.
The login I was given is only granted DBO permissions on this database.
I am trying to set this up so that the above stored procedure runs once
per month, so I naturally tried to set up a Job which would do this.
I have discovered from another group that:
"You cannot access a linked server from a TSQL jobstep if you aren't
sysadmin."
So: How can I automatically run this stored procedure once per month
under these conditions?
Thanks,
RyanIn SQL 2000, change the job owner to sysadmin.
In SQL 2005, change the job security context.
--
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another Certification Exam
<ryan_willow@.hotmail.com> wrote in message
news:1151015746.073933.305090@.r2g2000cwb.googlegroups.com...
>I have a stored procedure in a database on a server, and this stored
> procedure uses a linked server.
> The login I was given is only granted DBO permissions on this database.
> I am trying to set this up so that the above stored procedure runs once
> per month, so I naturally tried to set up a Job which would do this.
> I have discovered from another group that:
> "You cannot access a linked server from a TSQL jobstep if you aren't
> sysadmin."
> So: How can I automatically run this stored procedure once per month
> under these conditions?
> Thanks,
> Ryan
>|||I'm in SQL 2000.
I cannot change the job owner because my permissions do not allow this.
Apparently a dbo user named 'User' can only create a job with owner
'User'. I am trying to implement this without having to step outside
my dbo security level. Is this going to be possible, and if so how?
Thanks.
Arnie Rowland wrote:
> In SQL 2000, change the job owner to sysadmin.
> In SQL 2005, change the job security context.
> --
> Arnie Rowland, YACE*
> "To be successful, your heart must accompany your knowledge."
> *Yet Another Certification Exam
>
> <ryan_willow@.hotmail.com> wrote in message
> news:1151015746.073933.305090@.r2g2000cwb.googlegroups.com...
> >I have a stored procedure in a database on a server, and this stored
> > procedure uses a linked server.
> >
> > The login I was given is only granted DBO permissions on this database.
> >
> > I am trying to set this up so that the above stored procedure runs once
> > per month, so I naturally tried to set up a Job which would do this.
> >
> > I have discovered from another group that:
> > "You cannot access a linked server from a TSQL jobstep if you aren't
> > sysadmin."
> >
> > So: How can I automatically run this stored procedure once per month
> > under these conditions?
> >
> > Thanks,
> > Ryan
> >|||That will not be possible without coordination with the server
administrator. Since Jobs have the potential for significant performance
issues as well as security issues for the server, the security context for
Jobs is sysadmin. (in SQL2000).
And of course a SQL Server Administrator is probably not going to allow you
to have permission to create or change a job because of the potential that
it could execute any code or activity under the sysadmin security context.
Jobs are a 'Server' level activity -NOT a database level activity. Even if a
job is confined to a single database, it still operates as a server level
activity.
That changes with SQL 2005.
--
Arnie Rowland, YACE*
"To be successful, your heart must accompany your knowledge."
*Yet Another Certification Exam
"Ryan" <ryan_willow@.hotmail.com> wrote in message
news:1151017863.128715.208750@.g10g2000cwb.googlegroups.com...
> I'm in SQL 2000.
> I cannot change the job owner because my permissions do not allow this.
> Apparently a dbo user named 'User' can only create a job with owner
> 'User'. I am trying to implement this without having to step outside
> my dbo security level. Is this going to be possible, and if so how?
> Thanks.
> Arnie Rowland wrote:
>> In SQL 2000, change the job owner to sysadmin.
>> In SQL 2005, change the job security context.
>> --
>> Arnie Rowland, YACE*
>> "To be successful, your heart must accompany your knowledge."
>> *Yet Another Certification Exam
>>
>> <ryan_willow@.hotmail.com> wrote in message
>> news:1151015746.073933.305090@.r2g2000cwb.googlegroups.com...
>> >I have a stored procedure in a database on a server, and this stored
>> > procedure uses a linked server.
>> >
>> > The login I was given is only granted DBO permissions on this database.
>> >
>> > I am trying to set this up so that the above stored procedure runs once
>> > per month, so I naturally tried to set up a Job which would do this.
>> >
>> > I have discovered from another group that:
>> > "You cannot access a linked server from a TSQL jobstep if you aren't
>> > sysadmin."
>> >
>> > So: How can I automatically run this stored procedure once per month
>> > under these conditions?
>> >
>> > Thanks,
>> > Ryan
>> >
>|||Very informative, thanks Arnie.
Arnie Rowland wrote:
> That will not be possible without coordination with the server
> administrator. Since Jobs have the potential for significant performance
> issues as well as security issues for the server, the security context for
> Jobs is sysadmin. (in SQL2000).
> And of course a SQL Server Administrator is probably not going to allow you
> to have permission to create or change a job because of the potential that
> it could execute any code or activity under the sysadmin security context.
> Jobs are a 'Server' level activity -NOT a database level activity. Even if a
> job is confined to a single database, it still operates as a server level
> activity.
> That changes with SQL 2005.
> --
> Arnie Rowland, YACE*
> "To be successful, your heart must accompany your knowledge."
> *Yet Another Certification Exam
>
> "Ryan" <ryan_willow@.hotmail.com> wrote in message
> news:1151017863.128715.208750@.g10g2000cwb.googlegroups.com...
> > I'm in SQL 2000.
> >
> > I cannot change the job owner because my permissions do not allow this.
> > Apparently a dbo user named 'User' can only create a job with owner
> > 'User'. I am trying to implement this without having to step outside
> > my dbo security level. Is this going to be possible, and if so how?
> >
> > Thanks.
> >
> > Arnie Rowland wrote:
> >> In SQL 2000, change the job owner to sysadmin.
> >>
> >> In SQL 2005, change the job security context.
> >>
> >> --
> >> Arnie Rowland, YACE*
> >> "To be successful, your heart must accompany your knowledge."
> >>
> >> *Yet Another Certification Exam
> >>
> >>
> >> <ryan_willow@.hotmail.com> wrote in message
> >> news:1151015746.073933.305090@.r2g2000cwb.googlegroups.com...
> >> >I have a stored procedure in a database on a server, and this stored
> >> > procedure uses a linked server.
> >> >
> >> > The login I was given is only granted DBO permissions on this database.
> >> >
> >> > I am trying to set this up so that the above stored procedure runs once
> >> > per month, so I naturally tried to set up a Job which would do this.
> >> >
> >> > I have discovered from another group that:
> >> > "You cannot access a linked server from a TSQL jobstep if you aren't
> >> > sysadmin."
> >> >
> >> > So: How can I automatically run this stored procedure once per month
> >> > under these conditions?
> >> >
> >> > Thanks,
> >> > Ryan
> >> >
> >

Friday, February 24, 2012

Can't modify the UDFs I create

I am logged in using an account that is dbo on this database. I created a new UDF, which works fine (I can execute it). When I right click on it in the object explorer and select modify, it says:

Property AnsiNullStatus not available for UserDefinedFunction '[dbo].[fn_MVParamV]'. This property may not exists for this object or may not be retrievable due to insufficient access rights. (Microsoft.SqlServer.Smo)

I would think that if I had the rights to create, as well as use, the function then I should have rights to modify it. I get a similar error if I "script to new window as ALTER..."

This sounds like the following bug, which is scheduled to be fixed in Service Pack 1:
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=FDBK38845

Steve Kass
Drew University

Friday, February 10, 2012

can't get the complete list of tables owned by the dbo

Hi,

i am using sp_tables to get the list of the tables in the database owned by dbo

The database i am trying to query would let me query all the tables present in the database.there are almost a 1000 of them(owned by dbo) .I can query them and i get the records.

But the execution of the stored procedure "sp_tables" would return only 10 or so tables.I was puzzled by this.

can someone clarify this inconsistency.
thank youI'm not sure what is causing the behavior you see, but you can get a list of tables owned by dbo by doing this:

select * from sysobjects where type = 'U' and uid=1

This query will work correctly when ported to SQL 2005.|||Is dbo always 1?

isn't it safer to do:

select o.name from sysobjects o inner join sysusers u on o.uid = u.uid
where o.xtype = 'u' and u.name = 'dbo'|||

Hi,

As a purely practical matter, it is hard for me to imagine MSFT changing the dbo==1 relationship. However, you make an excellent point - AFAIK the BOL does not make an explicit guarantee, and it is best not to rely on hardcoding ID#s into your scripts.

Your query won't work on a case-sensitive server. I recommend this as the simplest

select * from sysobjects where type = 'U' and uid=user_id('dbo')

Notice that I am looking for user-created tables (type = 'U'). The list you get back in SQL 2005 is different than the list in SQL 2000.

Moreover, if you look for MSFT-created system objects (type='S')

select * from sysobjects where type = 'S' and uid=user_id('dbo')

You get back an empty set in SQL 2005 because all the system tables are now owned by the uid=user_id('sys'). Moreover, the system tables themselves are different in SQL 2005 than they are in SQL 2000. In fact, they are not even directly SELECT-able anymore. You must use the catalog views to query the catalog.

Hope this helps

|||

Would the best advice be to use the INFORMATION_SCHEMA.tables view?

select *
from INFORMATION_SCHEMA.TABLES
where TABLE_SCHEMA = 'dbo'

Most people shouldn't be looking up system tables like this anyhow, and this syntax works in 2000 and 2005 (7.0? can't remember) and should work in the next version, and the next, etc...

Moreover, the system tables themselves are different in SQL 2005 than they are in SQL 2000. In fact, they are not even directly SELECT-able anymore. You must use the catalog views to query the catalog.

I just wonder how stable these views will be in the future? I don't plan to use them in production code for anything. (other than monitoring, of course) The information_schema is supposed to be a stable/never subtracted from set of tables, right?

|||

USE pubs
GO

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA ='dbo'
AND TABLE_TYPE ='BASE TABLE' --If you leave this out you will also get VIEWS

Denis the SQL Menace

http://sqlservercode.blogspot.com/

|||Views are table too :) But yeah, I should have mentioned that too.|||

What is INFORMATION_SCHEMA ? Is it like a class ? As we are putting INFORMATION_SCHEMA.Table,etc.....

Can anyone explain ?

Thanks.

|||It is a special schema (in 2000 owner) used to contain metadata that is standard across platforms. It is kind of like DBO, but it is "special".|||

From BOL:

Information Schema Views

These views provide an internal, system table-independent view of the SQL Server meta data. Information schema views allow applications to work properly even though significant changes have been made to the system tables. The information schema views included in SQL Server conform to the SQL-92 Standard definition for the INFORMATION_SCHEMA.

SQL Server supports a three-part naming convention when referring to the current server. The SQL-92 standard also supports a three-part naming convention. However, the names used in both naming conventions are different. These views are defined in a special schema named INFORMATION_SCHEMA, which is contained in each database. Each INFORMATION_SCHEMA view contains meta data for all data objects stored in that particular database

This table describes the relationships between the SQL Server names and the SQL-92-standard names.

SQL Server name Maps to this equivalent SQL-92 name Database catalog Owner schema Object object user-defined data type domain

This naming convention mapping applies to these SQL Server SQL-92-compatible views. These views are defined in a special schema named INFORMATION_SCHEMA, which is contained in each database. Each INFORMATION_SCHEMA view contains meta data for all data objects stored in that particular database.

Denis the SQL Menace

http://sqlservercode.blogspot.com/

can't get the complete list of tables owned by the dbo

Hi,

i am using sp_tables to get the list of the tables in the database owned by dbo

The database i am trying to query would let me query all the tables present in the database.there are almost a 1000 of them(owned by dbo) .I can query them and i get the records.

But the execution of the stored procedure "sp_tables" would return only 10 or so tables.I was puzzled by this.

can someone clarify this inconsistency.
thank youI'm not sure what is causing the behavior you see, but you can get a list of tables owned by dbo by doing this:

select * from sysobjects where type = 'U' and uid=1

This query will work correctly when ported to SQL 2005.|||Is dbo always 1?

isn't it safer to do:

select o.name from sysobjects o inner join sysusers u on o.uid = u.uid
where o.xtype = 'u' and u.name = 'dbo'|||

Hi,

As a purely practical matter, it is hard for me to imagine MSFT changing the dbo==1 relationship. However, you make an excellent point - AFAIK the BOL does not make an explicit guarantee, and it is best not to rely on hardcoding ID#s into your scripts.

Your query won't work on a case-sensitive server. I recommend this as the simplest

select * from sysobjects where type = 'U' and uid=user_id('dbo')

Notice that I am looking for user-created tables (type = 'U'). The list you get back in SQL 2005 is different than the list in SQL 2000.

Moreover, if you look for MSFT-created system objects (type='S')

select * from sysobjects where type = 'S' and uid=user_id('dbo')

You get back an empty set in SQL 2005 because all the system tables are now owned by the uid=user_id('sys'). Moreover, the system tables themselves are different in SQL 2005 than they are in SQL 2000. In fact, they are not even directly SELECT-able anymore. You must use the catalog views to query the catalog.

Hope this helps

|||

Would the best advice be to use the INFORMATION_SCHEMA.tables view?

select *
from INFORMATION_SCHEMA.TABLES
where TABLE_SCHEMA = 'dbo'

Most people shouldn't be looking up system tables like this anyhow, and this syntax works in 2000 and 2005 (7.0? can't remember) and should work in the next version, and the next, etc...

Moreover, the system tables themselves are different in SQL 2005 than they are in SQL 2000. In fact, they are not even directly SELECT-able anymore. You must use the catalog views to query the catalog.

I just wonder how stable these views will be in the future? I don't plan to use them in production code for anything. (other than monitoring, of course) The information_schema is supposed to be a stable/never subtracted from set of tables, right?

|||

USE pubs
GO

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA ='dbo'
AND TABLE_TYPE ='BASE TABLE' --If you leave this out you will also get VIEWS

Denis the SQL Menace

http://sqlservercode.blogspot.com/

|||Views are table too :) But yeah, I should have mentioned that too.|||

What is INFORMATION_SCHEMA ? Is it like a class ? As we are putting INFORMATION_SCHEMA.Table,etc.....

Can anyone explain ?

Thanks.

|||It is a special schema (in 2000 owner) used to contain metadata that is standard across platforms. It is kind of like DBO, but it is "special".|||

From BOL:

Information Schema Views

These views provide an internal, system table-independent view of the SQL Server meta data. Information schema views allow applications to work properly even though significant changes have been made to the system tables. The information schema views included in SQL Server conform to the SQL-92 Standard definition for the INFORMATION_SCHEMA.

SQL Server supports a three-part naming convention when referring to the current server. The SQL-92 standard also supports a three-part naming convention. However, the names used in both naming conventions are different. These views are defined in a special schema named INFORMATION_SCHEMA, which is contained in each database. Each INFORMATION_SCHEMA view contains meta data for all data objects stored in that particular database

This table describes the relationships between the SQL Server names and the SQL-92-standard names.

SQL Server name Maps to this equivalent SQL-92 name Database catalog Owner schema Object object user-defined data type domain

This naming convention mapping applies to these SQL Server SQL-92-compatible views. These views are defined in a special schema named INFORMATION_SCHEMA, which is contained in each database. Each INFORMATION_SCHEMA view contains meta data for all data objects stored in that particular database.

Denis the SQL Menace

http://sqlservercode.blogspot.com/