Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Friday, March 30, 2012

Problem with sql2005 query/storedproc

I am working on the login portion of my app and am using my own setup for the moment so that I can learn more about how things work. I have 1 user setup in the db and am using a stored procedure to do the checking for me, here is the stored procedure code:

ALTER PROCEDUREdbo.MemberLogin(@.MemberNamenchar(20),

@.MemberPasswordnchar(15),

@.BoolLoginbit OUTPUT

)

AS

selectMemberPasswordfrommemberswheremembername = @.MemberNameandmemberpassword = @.MemberPassword

if@.@.Rowcount = 0

begin

selectBoolLogin = 0

return

end

selectBoolLogin=1

/* SET NOCOUNT ON */

RETURN

When I run my app, I continue to get login failed but no error messages. Can anybody help? Here is my vb code:

Dim MemberNameAsString

Dim MemberPasswordAsString

Dim BoolLoginAsBoolean

Dim DBConnectionAsNew Data.SqlClient.SqlConnection(MyCONNECTIONSTRING)

Dim SelectMembersAsNew Data.SqlClient.SqlCommand("MemberLogin", DBConnection)

SelectMembers.CommandType = Data.CommandType.StoredProcedure

MemberName = txtLogin.Text

MemberPassword = txtPassword.Text

Dim SelectMembersParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter

'Name

SelectMembersParameter.ParameterName ="@.MemberName"

SelectMembersParameter.Value = MemberName

SelectMembers.Parameters.Add(SelectMembersParameter)

'Password

Dim SelectPasswordParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter

SelectPasswordParameter.ParameterName ="@.MemberPassword"

SelectPasswordParameter.Value = MemberPassword

SelectMembers.Parameters.Add(SelectPasswordParameter)

Dim SelectReturnParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter

SelectReturnParameter.ParameterName ="@.BoolLogin"

SelectReturnParameter.Value = BoolLogin

SelectReturnParameter.Direction = Data.ParameterDirection.Output

SelectMembers.Parameters.Add(SelectReturnParameter)

If BoolLogin =FalseThen

MsgBox("Login Failed")

ElseIf BoolLogin =TrueThen

MsgBox("Login Successful")

EndIf

EndSub

Thank you!!!

Perhaps its because of the nchar's you are using. CHAR is used for a fixed width string so if you send in a string which is less than the specified length it will be padded with extra spaces at the end. I would modify your code as follows:

ALTER PROCEDURE dbo.MemberLogin(@.MemberNamenvarchar(20),@.MemberPasswordnvarchar(15),@.BoolLoginbit OUTPUT)ASBEGINSET NOCOUNT ON-- @.BoolLogin =0 ==> Does not exist, @.BoolLogin=1 ==> ExistsSET @.BoolLogin =0IFEXISTS(select MemberPasswordfrom memberswhere membername = @.MemberNameand memberpassword = @.MemberPassword)SET @.BoolLogin = 1SET NOCOUNT OFFEND
|||

Hello all, I am still having problems and am very frustrated. I have looked and ready over a dozen articles on ado/asp/sql and cannot seem to figure this out. I have a sql db I added using the add components part of asp. It is local, IIS is active. As far as i can tell servername is 'local'. This is the code I am running:

visual basic code:
Imports System.DataImports System.Data.SqlClientPartialClass _DefaultInherits System.Web.UI.PagePrivateConst MyCONNECTIONSTRINGAsString = "Server=(local);Database=Vex;Trusted_Connection=True"ProtectedSub btnLogin_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles btnLogin.ClickDim MemberNameAsStringDim MemberPasswordAsStringDim BoolLoginAsBooleanDim testAsStringDim DBConnectionAsNew Data.SqlClient.SqlConnection(MyCONNECTIONSTRING)Dim SelectMembersAsNew Data.SqlClient.SqlCommand("MemberLogin", DBConnection) SelectMembers.CommandType = Data.CommandType.StoredProcedure 'open the connection to the db DBConnection.Open() MemberName = txtLogin.Text MemberPassword = txtPassword.Text 'NameDim SelectMembersParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter SelectMembersParameter.ParameterName = "@.MemberName" SelectMembersParameter.Value = MemberName SelectMembers.Parameters.Add(SelectMembersParameter) 'PasswordDim SelectPasswordParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter SelectPasswordParameter.ParameterName = "@.MemberPassword" SelectPasswordParameter.Value = MemberPassword SelectMembers.Parameters.Add(SelectPasswordParameter) 'Pass or Fail VariableDim SelectReturnParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter SelectReturnParameter.ParameterName = "@.BoolLogin" SelectReturnParameter.Value = BoolLogin SelectReturnParameter.Direction = Data.ParameterDirection.Output SelectMembers.Parameters.Add(SelectReturnParameter) test = SelectMembers.ExecuteScalar()EndSubEndClass

I get this error when i try to login on the .open line:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

If i try to execute the .scalar w/o the line it tells me i need an open connection, but when I try to open the connection it throws this error. What am I doing wrong? Is there some setup piece(s) I am missing? I have gone through a basic install of vs2005 with no settings changes to sql05. Any help is greatly appreciated as I am at my wits end with this and I know it is going to be something simple......

as an added note, here is the connection string in the web.config file:

visual basic code:
<connectionStrings> <add name="csVex" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Vex.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings>
I went into sql2005 surface configuration and made sure all protocols are enabled. I am an admin locally on my machine. I do not know what else to check or do at this point.

Thanks for your help....

|||

Just in case anybody else runs into this. I created a new project and added a datasource to that project pointing to my sql 2005 database. I then copied the connectionstring from that connection and pasted it in my CONST connectionstring. Error went away.

Good Luck!!

Problem with SQL string using MS Access and OleDbConnection (ASP .NET)

The string concatination below works in the Query builder built-in to MS Access, but when I try it as an OleDbCommand it doesn't work.

SELECT ID, LastName + ', ' + FirstName AS Names FROM AgentNames;

Is there any other ways to return a combination like this using an OleDbCommand?

Thanks,

GrierOriginally posted by grier_allen
The string concatination below works in the Query builder built-in to MS Access, but when I try it as an OleDbCommand it doesn't work.

SELECT ID, LastName + ', ' + FirstName AS Names FROM AgentNames;

Is there any other ways to return a combination like this using an OleDbCommand?

Thanks,

Grier

Shot in the dark here but try [LastName + ',' + FirstName] as Names. If not, I dont know why that won't work.

Wednesday, March 28, 2012

Problem with SQL Server

A Stored Procedure has been running fine returning result in 2 secs but
surddenly started taking 2 mins to run. When I run the SQL codes in query
analyser it runs fine. Any idea what the problem may be?
Thanks
Egbon.Have a look at
INF: Troubleshooting Application Performance with SQL Server
http://support.microsoft.com/default.aspx?scid=kb;EN-US;224587
HOW TO: Troubleshoot Slow-Running Queries on SQL Server 7.0 or Later
http://support.microsoft.com/default.aspx?scid=kb;EN-US;243589
INF: Understanding and Resolving SQL Server 7.0
or 2000 Blocking Problems
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q224453
As well as these articles themselves, they contain links in them to lots
of other performace troubleshooting type articles. Lots of good stuff !
--
HTH
Jasper Smith (SQL Server MVP)
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"Egbon" <Vnjowusi@.gosps.com> wrote in message
news:uTma$F6WDHA.3248@.tk2msftngp13.phx.gbl...
A Stored Procedure has been running fine returning result in 2 secs but
surddenly started taking 2 mins to run. When I run the SQL codes in query
analyser it runs fine. Any idea what the problem may be?
Thanks
Egbon.|||Thanks for the links Jasper. My question was why will it run fine in Query
Analyzer and run slow in Stored Procedure. I can't understand.
Egbon.
"Jasper Smith" <jasper_smith9@.hotmail.com> wrote in message
news:OameON6WDHA.2256@.TK2MSFTNGP10.phx.gbl...
> Have a look at
> INF: Troubleshooting Application Performance with SQL Server
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;224587
> HOW TO: Troubleshoot Slow-Running Queries on SQL Server 7.0 or Later
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;243589
> INF: Understanding and Resolving SQL Server 7.0
> or 2000 Blocking Problems
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q224453
> As well as these articles themselves, they contain links in them to lots
> of other performace troubleshooting type articles. Lots of good stuff !
> --
> HTH
> Jasper Smith (SQL Server MVP)
> I support PASS - the definitive, global
> community for SQL Server professionals -
> http://www.sqlpass.org
> "Egbon" <Vnjowusi@.gosps.com> wrote in message
> news:uTma$F6WDHA.3248@.tk2msftngp13.phx.gbl...
> A Stored Procedure has been running fine returning result in 2 secs but
> surddenly started taking 2 mins to run. When I run the SQL codes in query
> analyser it runs fine. Any idea what the problem may be?
> Thanks
> Egbon.
>
>|||Do you mean it runs slow as a stored procedure in Query Analyzer ? i.e. if
you run the contents of the procedure in Query Analyzer does it run quicker
than the exec procedurename ? Sorry if I misunderstood you question, I
thought you meant that in general use by your application the performace of
this procedure was slow which may be cause by blocking etc so profiler would
help to show up the problem. You can also capture the execution plan and
look for differences between the slow and fast executions.
--
HTH
Jasper Smith (SQL Server MVP)
I support PASS - the definitive, global
community for SQL Server professionals -
http://www.sqlpass.org
"Egbon" <Vnjowusi@.gosps.com> wrote in message
news:eAVQIV6WDHA.2424@.TK2MSFTNGP12.phx.gbl...
Thanks for the links Jasper. My question was why will it run fine in Query
Analyzer and run slow in Stored Procedure. I can't understand.
Egbon.
"Jasper Smith" <jasper_smith9@.hotmail.com> wrote in message
news:OameON6WDHA.2256@.TK2MSFTNGP10.phx.gbl...
> Have a look at
> INF: Troubleshooting Application Performance with SQL Server
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;224587
> HOW TO: Troubleshoot Slow-Running Queries on SQL Server 7.0 or Later
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;243589
> INF: Understanding and Resolving SQL Server 7.0
> or 2000 Blocking Problems
> http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q224453
> As well as these articles themselves, they contain links in them to lots
> of other performace troubleshooting type articles. Lots of good stuff !
> --
> HTH
> Jasper Smith (SQL Server MVP)
> I support PASS - the definitive, global
> community for SQL Server professionals -
> http://www.sqlpass.org
> "Egbon" <Vnjowusi@.gosps.com> wrote in message
> news:uTma$F6WDHA.3248@.tk2msftngp13.phx.gbl...
> A Stored Procedure has been running fine returning result in 2 secs but
> surddenly started taking 2 mins to run. When I run the SQL codes in query
> analyser it runs fine. Any idea what the problem may be?
> Thanks
> Egbon.
>
>

Monday, March 26, 2012

problem with sql query.

Hi ya,

I have two tables. One is the temporary table called tbl_temp and the other is called tbl_empDetails.
I want to run a query that would bring me the records of tbl_temp where there is no corresponding ID present in tbl_empDetails, meaning it shud bring only records where a corresponding records is not available in tbl_empDetails. I tried it but this query doesn't work, it is bringing me the records which are there in tbl_empdetails. How can i do it?

SELECTDISTINCT tbl_temp.SID, tbl_temp.fname, tbl_temp.lname, tbl_temp.mail, tbl_temp.tel, tbl_temp.mobile, tbl_temp.office

FROM tbl_temp, tbl_empDetails where tbl_empDetails.adSID != tbl_temp.SID

ORDERBY tbl_temp.lname

Try this

SELECTDISTINCT *

FROMtbl_empDetails

where not tbl_empDetails.adSID in (select SID from tbl_temp)

|||

thank you very very much, you saved me lot of work.

Can you care to explain what you have done with the query and what I was doing wrong?

Just in case if i got any similar problem again.

Cheers

|||

Table 1

KeyValue

1

2

3

Table 2

KeyValue

1

2

If you use "where tbl_empDetails.adSID = tbl_temp.SID" you will get 2 record. (1,1) (2,2)

if you use "where tbl_empDetails.adSID != tbl_temp.SID" you will get 4 records. (1,2) (2,1) (3,1) (3,2)

So. I use sub-query to solve it !

|||

SELECTDISTINCT a.*

FROMtbl_temp a

LEFT JOIN tbl_empDetails b

ON a.SID = b.adSID

Where b.asSID IS NULL

This will run much faster than a sub-query if your tables are large...

Brad

Problem with sql query reformatting on its own

I'm having a problem with some of my reports in SQL reporting services.
After I enter my sql query, the software reformats removing parenthesis and
moving sections of the statement around. Is there a way I can force the
system to accept my query as is?Use the generic query designer (the button to switch to this is one of the
buttons to the right of the ...)
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Diane Chase via SQLMonster.com" <forum@.nospam.SQLMonster.com> wrote in
message news:cc800d5f7276462981022ea63d09d5a6@.SQLMonster.com...
> I'm having a problem with some of my reports in SQL reporting services.
> After I enter my sql query, the software reformats removing parenthesis
> and
> moving sections of the statement around. Is there a way I can force the
> system to accept my query as is?|||Thanks Bruce that worked!
--
Message posted via http://www.sqlmonster.com

Problem with SQL Query not moving through every record

I was wondering if anyone could quickly identify why the query is not parsing through each line in the temp table? I am sure its something stupid and easy, but if anyone has an idea, I would greatly appreciate the help!

My results are the same row repeated exactly the same for the number of rows in the temp table.

Declare @.Topic varchar(150)
Declare @.CustomTitle varchar(150)
Declare @.FullName varchar(100)
Declare @.starttime datetime
Declare @.endtime datetime

select
TOPIC = t.TopicName,
CustomTitle = e.ssCustomTitle,
StartTime = v.StartDateTime,
eFirstName = FirstName,
eLastName = LastName,
eEndTime = ssEndTime

INTO #tmpwork

FROM
brSession e
INNER JOIN v_SessionStartDateTime v on v.ssSessionId=e.ssSessionId
LEFT OUTER JOIN Topic t on t.TopicId=e.ssTopicId
LEFT JOIN brssPresenter ep ON (e.ssSessionID = ep.prSessionId)
LEFT OUTER JOIN Personnel p on p.PersonnelNbr=ep.prPerNbr
LEFT OUTER JOIN brVirtualRoom vr ON vr.vrBriefingId=e.ssBriefingId AND vr.vrVirtualRoomId=e.ssVirtualRoomId
LEFT OUTER JOIN brLocation bl ON bl.loBriefingId=vr.vrBriefingId AND bl.loVirtualRoomId=vr.vrVirtualRoomId
LEFT OUTER JOIN location BR ON BR.LocationId=bl.loLocationId
LEFT OUTER JOIN brssDetail1 dt on dt.dt1SessionId=e.ssSessionId
LEFT OUTER JOIN Competitor c on CompetitorId=dt.dt1CompetitorId
LEFT OUTER JOIN PresentationStyle ps ON ps.PresentationStyleId=dt.dt1PresentationStyleId
WHERE
e.ssBriefingID = 11749
and((not prConfirmModeId = 0) or (prPerNbr is null))
ORDER BY ssStartTime

SELECT @.Topic = Topic,
@.CustomTitle = CustomTitle,
@.FullName = eFirstname + ' ' + eLastName,
@.StartTime = starttime,
@.EndTime = eEndTime
From #tmpwork

IF (@.CustomTitle is not null)
IF (not @.CustomTitle = '') --correct problem of ZLS
Begin
set @.Topic = @.CustomTitle
End

SELECT
Topic = @.Topic,
StartTime = @.StartTime,
FullName = @.FullName,
EndTime = @.endtime

INTO #Final

FROM #tmpwork

select * from #Final

drop table #tmpwork
drop table #Final


SELECT @.Topic = Topic,

@.CustomTitle = CustomTitle,

@.FullName = eFirstname + ' ' + eLastName,

@.StartTime = starttime,

@.EndTime = eEndTime

From #tmpwork

... that doesn't give you an error? That's almost surprising. In this case, I'd have used either a loop or cursors to accomplish it.

Actually... you can combine so much of that into just one giant sql call rather than running temp tables and such.

select

TOPIC = IsNull(e.ssCustomTitle, t.TopicName)
StartTime = v.StartDateTime,
FullName = FirstName + ' ' + LastName,
eEndTime = ssEndTime
INTO #tmpwork
FROM
brSession e
INNER JOIN v_SessionStartDateTime v on v.ssSessionId=e.ssSessionId
LEFT OUTER JOIN Topic t on t.TopicId=e.ssTopicId
LEFT JOIN brssPresenter ep ON (e.ssSessionID = ep.prSessionId)
LEFT OUTER JOIN Personnel p on p.PersonnelNbr=ep.prPerNbr
LEFT OUTER JOIN brVirtualRoom vr ON vr.vrBriefingId=e.ssBriefingId AND vr.vrVirtualRoomId=e.ssVirtualRoomId
LEFT OUTER JOIN brLocation bl ON bl.loBriefingId=vr.vrBriefingId AND bl.loVirtualRoomId=vr.vrVirtualRoomId
LEFT OUTER JOIN location BR ON BR.LocationId=bl.loLocationId
LEFT OUTER JOIN brssDetail1 dt on dt.dt1SessionId=e.ssSessionId
LEFT OUTER JOIN Competitor c on CompetitorId=dt.dt1CompetitorId
LEFT OUTER JOIN PresentationStyle ps ON ps.PresentationStyleId=dt.dt1PresentationStyleId

WHERE

e.ssBriefingID = 11749
and((not prConfirmModeId = 0) or (prPerNbr is null))

ORDER BY ssStartTime

seems easier than having that and another temp table just to do one or two things.

look into IIF(expression, true, false) and IsNull(field, replacement) methods to streamline your sql to optimum executions.

books online is also a good source of information.|||Thanks for the help. This forum has saved my butt on countless occasions.

The reason I was going through and creating the second temp table was because I needed it to write the word 'Multiple' if the Topic had to speakers (fullName). So my thought was to simply do the first one where I get just the data I want, and on the second table go through and convert the Data into the format I needed it. Im sure there is a way to convert the data on its way into the first tmp table, however I am not sure of the best way to approach it.|||I ended up making the second temp table to accomplish the task. Perhaps there is an easier way, but this seemed to be the easiest way to do it. FWIW, here is the finished code, maybe it will help someone else as well.


DECLARE @.Topic varchar(100)
DECLARE @.CustomTitle varchar(150)
DECLARE @.starttime datetime
DECLARE @.tmpname varchar(100)
DECLARE @.eventno int
DECLARE @.endtime datetime
select

TOPIC = IsNull(e.ssCustomTitle, t.TopicName),
StartTime = v.StartDateTime,
FullName = FirstName + ' ' + LastName,
EndTime = ssEndTime,
EventNo = e.ssSessionId
INTO #tmpwork
FROM
brSession e
INNER JOIN v_SessionStartDateTime v on v.ssSessionId=e.ssSessionId
LEFT OUTER JOIN Topic t on t.TopicId=e.ssTopicId
LEFT JOIN brssPresenter ep ON (e.ssSessionID = ep.prSessionId)
LEFT OUTER JOIN Personnel p on p.PersonnelNbr=ep.prPerNbr
LEFT OUTER JOIN brVirtualRoom vr ON vr.vrBriefingId=e.ssBriefingId AND vr.vrVirtualRoomId=e.ssVirtualRoomId
LEFT OUTER JOIN brLocation bl ON bl.loBriefingId=vr.vrBriefingId AND bl.loVirtualRoomId=vr.vrVirtualRoomId
LEFT OUTER JOIN location BR ON BR.LocationId=bl.loLocationId
LEFT OUTER JOIN brssDetail1 dt on dt.dt1SessionId=e.ssSessionId
LEFT OUTER JOIN Competitor c on CompetitorId=dt.dt1CompetitorId
LEFT OUTER JOIN PresentationStyle ps ON ps.PresentationStyleId=dt.dt1PresentationStyleId

WHERE

e.ssBriefingID = 11749
and((not prConfirmModeId = 0) or (prPerNbr is null))

ORDER BY ssStartTime

Create Table #Final(
Topic varchar(180),
StartTime datetime,
FullName varchar(100) NULL,
EventNo int,
EndTime datetime, RoomNo int
)

If (Select Count(*) From #tmpwork) > 0
Begin

While (Select Count(*) From #tmpwork) > 0
Begin

Select @.topic = Topic,
@.starttime = StartTime,
@.tmpname = FullName,
@.eventno = EventNo,
@.endtime = EndTime
From #tmpwork

If (Select Count(*) From #tmpwork Where EventNo = @.eventno) > 1
Insert Into #Final Values(@.topic, @.starttime, 'Multiple', @.eventno, @.endtime, null)
Else
Insert Into #Final Values(@.topic, @.starttime, @.tmpname, @.eventno, @.endtime, null)

Delete #tmpwork Where EventNo = @.eventno

End
End

Select EventNo,
[Time] = SubString(Convert(varchar(20), StartTime), 13, 8),
EndTime = SubString(Convert(varchar(20), EndTime), 13, 8),
Topic,
FullName,
[Date] = Convert(varchar(20), StartTime, 107),
[WeekDay] = Datename(weekday,StartTime)

From #Final
Order By StartTime, EventNo

Drop Table #tmpwork
DROP Table #Final

sql

Problem with SQL Query file

I'm hoping you can help with something.
I've installed the Project Server post SP1 Hotfix in my test lab and all
looks ok, apart from some errors when I execute the websps.sql query file
that forms part of the hotfix. The errors look like this.
There is no such user or group 'MSProjectServerRole'.
Here's an example of one of the entries in the query file that generates the
error.
/* Query #65005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
AS
select WADMIN_SMTP_SERVER_NAME,
WADMIN_SMTP_SERVER_PORT,
WADMIN_DEFAULT_LANGUAGE,
WADMIN_NTFY_FROM_EMAIL,
WADMIN_NTFY_EMAIL_TRAILER,
WADMIN_ORG_EMAIL_ADDRESS,
WADMIN_NPE_LAST_RUN,
WADMIN_NPE_NEXT_RUN,
WADMIN_NPE_SCHEDULED_TIME,
WADMIN_INTRANET_SERVER_URL,
WADMIN_EXTRANET_SERVER_URL,
WADMIN_EMAIL_CHARSET
from MSP_WEB_ADMIN
RETURN
GO
GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
MSProjectServerRole
GO
********************************
I've checked that the MSProjectServerRole exists and is populated with
MSProjectServerUser, so all looks ok. I'm confused as to why the execution
of the stored procedure comes up with the error. The CREATE PROCEDURE part
doesn't appear to work as the stored procedure
MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise Manager
after the query file has finished executing.
Not being a SQL guy, can anyone give me a pointer as to how I can
troubleshoot this problem? I'm executing the query file as sa, so I don't
think this is a permissions thing.
Thanks
Tony
It appears that you created the proc in the wrong database. Likely, you put
it in master.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
I'm hoping you can help with something.
I've installed the Project Server post SP1 Hotfix in my test lab and all
looks ok, apart from some errors when I execute the websps.sql query file
that forms part of the hotfix. The errors look like this.
There is no such user or group 'MSProjectServerRole'.
Here's an example of one of the entries in the query file that generates the
error.
/* Query #65005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
AS
select WADMIN_SMTP_SERVER_NAME,
WADMIN_SMTP_SERVER_PORT,
WADMIN_DEFAULT_LANGUAGE,
WADMIN_NTFY_FROM_EMAIL,
WADMIN_NTFY_EMAIL_TRAILER,
WADMIN_ORG_EMAIL_ADDRESS,
WADMIN_NPE_LAST_RUN,
WADMIN_NPE_NEXT_RUN,
WADMIN_NPE_SCHEDULED_TIME,
WADMIN_INTRANET_SERVER_URL,
WADMIN_EXTRANET_SERVER_URL,
WADMIN_EMAIL_CHARSET
from MSP_WEB_ADMIN
RETURN
GO
GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
MSProjectServerRole
GO
********************************
I've checked that the MSProjectServerRole exists and is populated with
MSProjectServerUser, so all looks ok. I'm confused as to why the execution
of the stored procedure comes up with the error. The CREATE PROCEDURE part
doesn't appear to work as the stored procedure
MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
Manager
after the query file has finished executing.
Not being a SQL guy, can anyone give me a pointer as to how I can
troubleshoot this problem? I'm executing the query file as sa, so I don't
think this is a permissions thing.
Thanks
Tony
|||Thanks Tom, you were spot-on :-) I had highlighted the ProjectServer
database in the left hand pane of Query Analyzer, but had not specified it in
the drop down list in the right pane.
Tony
"Tom Moreau" wrote:

> It appears that you created the proc in the wrong database. Likely, you put
> it in master.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> ..
> "Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
> news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
> I'm hoping you can help with something.
> I've installed the Project Server post SP1 Hotfix in my test lab and all
> looks ok, apart from some errors when I execute the websps.sql query file
> that forms part of the hotfix. The errors look like this.
> There is no such user or group 'MSProjectServerRole'.
> Here's an example of one of the entries in the query file that generates the
> error.
> /* Query #65005 */
> CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
> AS
> select WADMIN_SMTP_SERVER_NAME,
> WADMIN_SMTP_SERVER_PORT,
> WADMIN_DEFAULT_LANGUAGE,
> WADMIN_NTFY_FROM_EMAIL,
> WADMIN_NTFY_EMAIL_TRAILER,
> WADMIN_ORG_EMAIL_ADDRESS,
> WADMIN_NPE_LAST_RUN,
> WADMIN_NPE_NEXT_RUN,
> WADMIN_NPE_SCHEDULED_TIME,
> WADMIN_INTRANET_SERVER_URL,
> WADMIN_EXTRANET_SERVER_URL,
> WADMIN_EMAIL_CHARSET
> from MSP_WEB_ADMIN
> RETURN
> GO
> GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
> MSProjectServerRole
> GO
> ********************************
> I've checked that the MSProjectServerRole exists and is populated with
> MSProjectServerUser, so all looks ok. I'm confused as to why the execution
> of the stored procedure comes up with the error. The CREATE PROCEDURE part
> doesn't appear to work as the stored procedure
> MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
> Manager
> after the query file has finished executing.
> Not being a SQL guy, can anyone give me a pointer as to how I can
> troubleshoot this problem? I'm executing the query file as sa, so I don't
> think this is a permissions thing.
> Thanks
> Tony
>
|||It's a common problem with DBA's. We usually belong to the sysadmin role
and have a default DB of master. If you include a USE statement, that can
fend off the wrong DB problem. Any object you create should also have the
appropriate GRANT statements, too. When you're in sysadmin, it always
works.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
news:209BE0C0-C948-4AE6-886E-F87A76AC3823@.microsoft.com...
Thanks Tom, you were spot-on :-) I had highlighted the ProjectServer
database in the left hand pane of Query Analyzer, but had not specified it
in
the drop down list in the right pane.
Tony
"Tom Moreau" wrote:

> It appears that you created the proc in the wrong database. Likely, you
> put
> it in master.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> ..
> "Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
> news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
> I'm hoping you can help with something.
> I've installed the Project Server post SP1 Hotfix in my test lab and all
> looks ok, apart from some errors when I execute the websps.sql query file
> that forms part of the hotfix. The errors look like this.
> There is no such user or group 'MSProjectServerRole'.
> Here's an example of one of the entries in the query file that generates
> the
> error.
> /* Query #65005 */
> CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
> AS
> select WADMIN_SMTP_SERVER_NAME,
> WADMIN_SMTP_SERVER_PORT,
> WADMIN_DEFAULT_LANGUAGE,
> WADMIN_NTFY_FROM_EMAIL,
> WADMIN_NTFY_EMAIL_TRAILER,
> WADMIN_ORG_EMAIL_ADDRESS,
> WADMIN_NPE_LAST_RUN,
> WADMIN_NPE_NEXT_RUN,
> WADMIN_NPE_SCHEDULED_TIME,
> WADMIN_INTRANET_SERVER_URL,
> WADMIN_EXTRANET_SERVER_URL,
> WADMIN_EMAIL_CHARSET
> from MSP_WEB_ADMIN
> RETURN
> GO
> GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
> MSProjectServerRole
> GO
> ********************************
> I've checked that the MSProjectServerRole exists and is populated with
> MSProjectServerUser, so all looks ok. I'm confused as to why the
> execution
> of the stored procedure comes up with the error. The CREATE PROCEDURE
> part
> doesn't appear to work as the stored procedure
> MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
> Manager
> after the query file has finished executing.
> Not being a SQL guy, can anyone give me a pointer as to how I can
> troubleshoot this problem? I'm executing the query file as sa, so I don't
> think this is a permissions thing.
> Thanks
> Tony
>

Problem with SQL Query file

I'm hoping you can help with something.
I've installed the Project Server post SP1 Hotfix in my test lab and all
looks ok, apart from some errors when I execute the websps.sql query file
that forms part of the hotfix. The errors look like this.
There is no such user or group 'MSProjectServerRole'.
Here's an example of one of the entries in the query file that generates the
error.
/* Query #65005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
AS
select WADMIN_SMTP_SERVER_NAME,
WADMIN_SMTP_SERVER_PORT,
WADMIN_DEFAULT_LANGUAGE,
WADMIN_NTFY_FROM_EMAIL,
WADMIN_NTFY_EMAIL_TRAILER,
WADMIN_ORG_EMAIL_ADDRESS,
WADMIN_NPE_LAST_RUN,
WADMIN_NPE_NEXT_RUN,
WADMIN_NPE_SCHEDULED_TIME,
WADMIN_INTRANET_SERVER_URL,
WADMIN_EXTRANET_SERVER_URL,
WADMIN_EMAIL_CHARSET
from MSP_WEB_ADMIN
RETURN
GO
GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
MSProjectServerRole
GO
********************************
I've checked that the MSProjectServerRole exists and is populated with
MSProjectServerUser, so all looks ok. I'm confused as to why the execution
of the stored procedure comes up with the error. The CREATE PROCEDURE part
doesn't appear to work as the stored procedure
MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise Manage
r
after the query file has finished executing.
Not being a SQL guy, can anyone give me a pointer as to how I can
troubleshoot this problem? I'm executing the query file as sa, so I don't
think this is a permissions thing.
Thanks
TonyIt appears that you created the proc in the wrong database. Likely, you put
it in master.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
I'm hoping you can help with something.
I've installed the Project Server post SP1 Hotfix in my test lab and all
looks ok, apart from some errors when I execute the websps.sql query file
that forms part of the hotfix. The errors look like this.
There is no such user or group 'MSProjectServerRole'.
Here's an example of one of the entries in the query file that generates the
error.
/* Query #65005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
AS
select WADMIN_SMTP_SERVER_NAME,
WADMIN_SMTP_SERVER_PORT,
WADMIN_DEFAULT_LANGUAGE,
WADMIN_NTFY_FROM_EMAIL,
WADMIN_NTFY_EMAIL_TRAILER,
WADMIN_ORG_EMAIL_ADDRESS,
WADMIN_NPE_LAST_RUN,
WADMIN_NPE_NEXT_RUN,
WADMIN_NPE_SCHEDULED_TIME,
WADMIN_INTRANET_SERVER_URL,
WADMIN_EXTRANET_SERVER_URL,
WADMIN_EMAIL_CHARSET
from MSP_WEB_ADMIN
RETURN
GO
GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
MSProjectServerRole
GO
********************************
I've checked that the MSProjectServerRole exists and is populated with
MSProjectServerUser, so all looks ok. I'm confused as to why the execution
of the stored procedure comes up with the error. The CREATE PROCEDURE part
doesn't appear to work as the stored procedure
MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
Manager
after the query file has finished executing.
Not being a SQL guy, can anyone give me a pointer as to how I can
troubleshoot this problem? I'm executing the query file as sa, so I don't
think this is a permissions thing.
Thanks
Tony|||Thanks Tom, you were spot-on :-) I had highlighted the ProjectServer
database in the left hand pane of Query Analyzer, but had not specified it i
n
the drop down list in the right pane.
Tony
"Tom Moreau" wrote:

> It appears that you created the proc in the wrong database. Likely, you p
ut
> it in master.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> ..
> "Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
> news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
> I'm hoping you can help with something.
> I've installed the Project Server post SP1 Hotfix in my test lab and all
> looks ok, apart from some errors when I execute the websps.sql query file
> that forms part of the hotfix. The errors look like this.
> There is no such user or group 'MSProjectServerRole'.
> Here's an example of one of the entries in the query file that generates t
he
> error.
> /* Query #65005 */
> CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
> AS
> select WADMIN_SMTP_SERVER_NAME,
> WADMIN_SMTP_SERVER_PORT,
> WADMIN_DEFAULT_LANGUAGE,
> WADMIN_NTFY_FROM_EMAIL,
> WADMIN_NTFY_EMAIL_TRAILER,
> WADMIN_ORG_EMAIL_ADDRESS,
> WADMIN_NPE_LAST_RUN,
> WADMIN_NPE_NEXT_RUN,
> WADMIN_NPE_SCHEDULED_TIME,
> WADMIN_INTRANET_SERVER_URL,
> WADMIN_EXTRANET_SERVER_URL,
> WADMIN_EMAIL_CHARSET
> from MSP_WEB_ADMIN
> RETURN
> GO
> GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
> MSProjectServerRole
> GO
> ********************************
> I've checked that the MSProjectServerRole exists and is populated with
> MSProjectServerUser, so all looks ok. I'm confused as to why the executio
n
> of the stored procedure comes up with the error. The CREATE PROCEDURE pa
rt
> doesn't appear to work as the stored procedure
> MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
> Manager
> after the query file has finished executing.
> Not being a SQL guy, can anyone give me a pointer as to how I can
> troubleshoot this problem? I'm executing the query file as sa, so I don't
> think this is a permissions thing.
> Thanks
> Tony
>|||It's a common problem with DBA's. We usually belong to the sysadmin role
and have a default DB of master. If you include a USE statement, that can
fend off the wrong DB problem. Any object you create should also have the
appropriate GRANT statements, too. When you're in sysadmin, it always
works.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
news:209BE0C0-C948-4AE6-886E-F87A76AC3823@.microsoft.com...
Thanks Tom, you were spot-on :-) I had highlighted the ProjectServer
database in the left hand pane of Query Analyzer, but had not specified it
in
the drop down list in the right pane.
Tony
"Tom Moreau" wrote:

> It appears that you created the proc in the wrong database. Likely, you
> put
> it in master.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> ..
> "Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
> news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
> I'm hoping you can help with something.
> I've installed the Project Server post SP1 Hotfix in my test lab and all
> looks ok, apart from some errors when I execute the websps.sql query file
> that forms part of the hotfix. The errors look like this.
> There is no such user or group 'MSProjectServerRole'.
> Here's an example of one of the entries in the query file that generates
> the
> error.
> /* Query #65005 */
> CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
> AS
> select WADMIN_SMTP_SERVER_NAME,
> WADMIN_SMTP_SERVER_PORT,
> WADMIN_DEFAULT_LANGUAGE,
> WADMIN_NTFY_FROM_EMAIL,
> WADMIN_NTFY_EMAIL_TRAILER,
> WADMIN_ORG_EMAIL_ADDRESS,
> WADMIN_NPE_LAST_RUN,
> WADMIN_NPE_NEXT_RUN,
> WADMIN_NPE_SCHEDULED_TIME,
> WADMIN_INTRANET_SERVER_URL,
> WADMIN_EXTRANET_SERVER_URL,
> WADMIN_EMAIL_CHARSET
> from MSP_WEB_ADMIN
> RETURN
> GO
> GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
> MSProjectServerRole
> GO
> ********************************
> I've checked that the MSProjectServerRole exists and is populated with
> MSProjectServerUser, so all looks ok. I'm confused as to why the
> execution
> of the stored procedure comes up with the error. The CREATE PROCEDURE
> part
> doesn't appear to work as the stored procedure
> MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
> Manager
> after the query file has finished executing.
> Not being a SQL guy, can anyone give me a pointer as to how I can
> troubleshoot this problem? I'm executing the query file as sa, so I don't
> think this is a permissions thing.
> Thanks
> Tony
>

Problem with SQL Query file

I'm hoping you can help with something.
I've installed the Project Server post SP1 Hotfix in my test lab and all
looks ok, apart from some errors when I execute the websps.sql query file
that forms part of the hotfix. The errors look like this.
There is no such user or group 'MSProjectServerRole'.
Here's an example of one of the entries in the query file that generates the
error.
/* Query #65005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
AS
select WADMIN_SMTP_SERVER_NAME,
WADMIN_SMTP_SERVER_PORT,
WADMIN_DEFAULT_LANGUAGE,
WADMIN_NTFY_FROM_EMAIL,
WADMIN_NTFY_EMAIL_TRAILER,
WADMIN_ORG_EMAIL_ADDRESS,
WADMIN_NPE_LAST_RUN,
WADMIN_NPE_NEXT_RUN,
WADMIN_NPE_SCHEDULED_TIME,
WADMIN_INTRANET_SERVER_URL,
WADMIN_EXTRANET_SERVER_URL,
WADMIN_EMAIL_CHARSET
from MSP_WEB_ADMIN
RETURN
GO
GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
MSProjectServerRole
GO
********************************
I've checked that the MSProjectServerRole exists and is populated with
MSProjectServerUser, so all looks ok. I'm confused as to why the execution
of the stored procedure comes up with the error. The CREATE PROCEDURE part
doesn't appear to work as the stored procedure
MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise Manager
after the query file has finished executing.
Not being a SQL guy, can anyone give me a pointer as to how I can
troubleshoot this problem? I'm executing the query file as sa, so I don't
think this is a permissions thing.
Thanks
TonyIt appears that you created the proc in the wrong database. Likely, you put
it in master.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
I'm hoping you can help with something.
I've installed the Project Server post SP1 Hotfix in my test lab and all
looks ok, apart from some errors when I execute the websps.sql query file
that forms part of the hotfix. The errors look like this.
There is no such user or group 'MSProjectServerRole'.
Here's an example of one of the entries in the query file that generates the
error.
/* Query #65005 */
CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
AS
select WADMIN_SMTP_SERVER_NAME,
WADMIN_SMTP_SERVER_PORT,
WADMIN_DEFAULT_LANGUAGE,
WADMIN_NTFY_FROM_EMAIL,
WADMIN_NTFY_EMAIL_TRAILER,
WADMIN_ORG_EMAIL_ADDRESS,
WADMIN_NPE_LAST_RUN,
WADMIN_NPE_NEXT_RUN,
WADMIN_NPE_SCHEDULED_TIME,
WADMIN_INTRANET_SERVER_URL,
WADMIN_EXTRANET_SERVER_URL,
WADMIN_EMAIL_CHARSET
from MSP_WEB_ADMIN
RETURN
GO
GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
MSProjectServerRole
GO
********************************
I've checked that the MSProjectServerRole exists and is populated with
MSProjectServerUser, so all looks ok. I'm confused as to why the execution
of the stored procedure comes up with the error. The CREATE PROCEDURE part
doesn't appear to work as the stored procedure
MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
Manager
after the query file has finished executing.
Not being a SQL guy, can anyone give me a pointer as to how I can
troubleshoot this problem? I'm executing the query file as sa, so I don't
think this is a permissions thing.
Thanks
Tony|||Thanks Tom, you were spot-on :-) I had highlighted the ProjectServer
database in the left hand pane of Query Analyzer, but had not specified it in
the drop down list in the right pane.
Tony
"Tom Moreau" wrote:
> It appears that you created the proc in the wrong database. Likely, you put
> it in master.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> ..
> "Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
> news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
> I'm hoping you can help with something.
> I've installed the Project Server post SP1 Hotfix in my test lab and all
> looks ok, apart from some errors when I execute the websps.sql query file
> that forms part of the hotfix. The errors look like this.
> There is no such user or group 'MSProjectServerRole'.
> Here's an example of one of the entries in the query file that generates the
> error.
> /* Query #65005 */
> CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
> AS
> select WADMIN_SMTP_SERVER_NAME,
> WADMIN_SMTP_SERVER_PORT,
> WADMIN_DEFAULT_LANGUAGE,
> WADMIN_NTFY_FROM_EMAIL,
> WADMIN_NTFY_EMAIL_TRAILER,
> WADMIN_ORG_EMAIL_ADDRESS,
> WADMIN_NPE_LAST_RUN,
> WADMIN_NPE_NEXT_RUN,
> WADMIN_NPE_SCHEDULED_TIME,
> WADMIN_INTRANET_SERVER_URL,
> WADMIN_EXTRANET_SERVER_URL,
> WADMIN_EMAIL_CHARSET
> from MSP_WEB_ADMIN
> RETURN
> GO
> GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
> MSProjectServerRole
> GO
> ********************************
> I've checked that the MSProjectServerRole exists and is populated with
> MSProjectServerUser, so all looks ok. I'm confused as to why the execution
> of the stored procedure comes up with the error. The CREATE PROCEDURE part
> doesn't appear to work as the stored procedure
> MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
> Manager
> after the query file has finished executing.
> Not being a SQL guy, can anyone give me a pointer as to how I can
> troubleshoot this problem? I'm executing the query file as sa, so I don't
> think this is a permissions thing.
> Thanks
> Tony
>|||It's a common problem with DBA's. We usually belong to the sysadmin role
and have a default DB of master. If you include a USE statement, that can
fend off the wrong DB problem. Any object you create should also have the
appropriate GRANT statements, too. When you're in sysadmin, it always
works.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
news:209BE0C0-C948-4AE6-886E-F87A76AC3823@.microsoft.com...
Thanks Tom, you were spot-on :-) I had highlighted the ProjectServer
database in the left hand pane of Query Analyzer, but had not specified it
in
the drop down list in the right pane.
Tony
"Tom Moreau" wrote:
> It appears that you created the proc in the wrong database. Likely, you
> put
> it in master.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> ..
> "Tony Murray" <TonyMurray@.discussions.microsoft.com> wrote in message
> news:1530354A-94BA-4F8C-B1E7-F31980B603A9@.microsoft.com...
> I'm hoping you can help with something.
> I've installed the Project Server post SP1 Hotfix in my test lab and all
> looks ok, apart from some errors when I execute the websps.sql query file
> that forms part of the hotfix. The errors look like this.
> There is no such user or group 'MSProjectServerRole'.
> Here's an example of one of the entries in the query file that generates
> the
> error.
> /* Query #65005 */
> CREATE PROCEDURE dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo
> AS
> select WADMIN_SMTP_SERVER_NAME,
> WADMIN_SMTP_SERVER_PORT,
> WADMIN_DEFAULT_LANGUAGE,
> WADMIN_NTFY_FROM_EMAIL,
> WADMIN_NTFY_EMAIL_TRAILER,
> WADMIN_ORG_EMAIL_ADDRESS,
> WADMIN_NPE_LAST_RUN,
> WADMIN_NPE_NEXT_RUN,
> WADMIN_NPE_SCHEDULED_TIME,
> WADMIN_INTRANET_SERVER_URL,
> WADMIN_EXTRANET_SERVER_URL,
> WADMIN_EMAIL_CHARSET
> from MSP_WEB_ADMIN
> RETURN
> GO
> GRANT EXECUTE ON dbo.MSP_WEB_SP_QRY_GetNotificationAdminInfo TO
> MSProjectServerRole
> GO
> ********************************
> I've checked that the MSProjectServerRole exists and is populated with
> MSProjectServerUser, so all looks ok. I'm confused as to why the
> execution
> of the stored procedure comes up with the error. The CREATE PROCEDURE
> part
> doesn't appear to work as the stored procedure
> MSP_WEB_SP_QRY_GetNotificationAdminInfo does not appear in Enterprise
> Manager
> after the query file has finished executing.
> Not being a SQL guy, can anyone give me a pointer as to how I can
> troubleshoot this problem? I'm executing the query file as sa, so I don't
> think this is a permissions thing.
> Thanks
> Tony
>

Problem with SQL Query Analyzer

Hi,
I have the following problem: if I call a stored procedure from a program (via COM+/OLE DB) I measure the response time and I get something around 400 ms (including reading the data from the result set, a couple of MoveNext operations).
Now if I call the very same stored procedure within the SQL Query Analyzer, it takes almost 8 seconds until I can see the results! Does anybody know why?
Is the Query Analyzer so badly implemented when it reads the results and displays them?
Even if I eliminate the results (by adding select top 0 in my final query in the stored procedure) it still takes about 7 seconds within the Query Analyzer.
My bigger problem is that I use the query analyzer to fine-tune my application and it seems I can't rely on the results, because the same queries run differently once they are called from the application.
It's weird because I also get these confusing response times displayed in the Profiler! At the beginning I thought that the Query Analyzer adds some overhead, but why do I get different times in the Profiler?
Any hints/tips? Did anyone experience that before?
Thanks in advance,
Florin Micle
Execution plans can differ for several reasons. Different SET option is one potential reason. The first thing
to do is to compare the execution plans and see if they are the same or not.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"fmicle" <fmicle@.hotmail.com> wrote in message news:824E53F3-AC7C-4C1C-AFD5-06D4609F8714@.microsoft.com...
> Hi,
> I have the following problem: if I call a stored procedure from a program (via COM+/OLE DB) I measure the
response time and I get something around 400 ms (including reading the data from the result set, a couple of
MoveNext operations).
> Now if I call the very same stored procedure within the SQL Query Analyzer, it takes almost 8 seconds until
I can see the results! Does anybody know why?
> Is the Query Analyzer so badly implemented when it reads the results and displays them?
> Even if I eliminate the results (by adding select top 0 in my final query in the stored procedure) it still
takes about 7 seconds within the Query Analyzer.
> My bigger problem is that I use the query analyzer to fine-tune my application and it seems I can't rely on
the results, because the same queries run differently once they are called from the application.
> It's weird because I also get these confusing response times displayed in the Profiler! At the beginning I
thought that the Query Analyzer adds some overhead, but why do I get different times in the Profiler?
> Any hints/tips? Did anyone experience that before?
> Thanks in advance,
> Florin Micle
|||Perhaps your data happened to be cached in some instances. Try clearing the
cache using DBCC DROPCLEANBUFFERS before testing the queries using.
As Tibor mentioned, different execution plans may be another cause, which
you can also capture using Profiler.
Regards
Ray Mond
"fmicle" <fmicle@.hotmail.com> wrote in message
news:824E53F3-AC7C-4C1C-AFD5-06D4609F8714@.microsoft.com...
> Hi,
> I have the following problem: if I call a stored procedure from a program
(via COM+/OLE DB) I measure the response time and I get something around 400
ms (including reading the data from the result set, a couple of MoveNext
operations).
> Now if I call the very same stored procedure within the SQL Query
Analyzer, it takes almost 8 seconds until I can see the results! Does
anybody know why?
> Is the Query Analyzer so badly implemented when it reads the results and
displays them?
> Even if I eliminate the results (by adding select top 0 in my final query
in the stored procedure) it still takes about 7 seconds within the Query
Analyzer.
> My bigger problem is that I use the query analyzer to fine-tune my
application and it seems I can't rely on the results, because the same
queries run differently once they are called from the application.
> It's weird because I also get these confusing response times displayed in
the Profiler! At the beginning I thought that the Query Analyzer adds some
overhead, but why do I get different times in the Profiler?
> Any hints/tips? Did anyone experience that before?
> Thanks in advance,
> Florin Micle
|||Hi, when you look at profiler do you to capture exactly what it being run when the program calls the sp? I ask because unless the inputs are exactly the same you could get differing results. I've seen this with datetime inputs where query plans have been
different depending on the format of the date input. As Tibor says, did the query plan show anything different? I assume they must have done? You've tried the TOP 0 which should eliminate the displaying of the results and as Ray says you can drop the data
from cache (and run CHECKPOINT) to give the two approaches a level playing field. I feel the answer will be in your execution plan and I'd expect either as Tibor says, your SET options will be the root, or that it's perhaps something to do with one or mo
re of your sp inputs.
Alicia
Http://www.sqlporn.co.uk
|||Well, how am I suppose to know how exactly the query is executed and which query plan is taken?
I can see in the Profiler, that the exact same query is launched when I call it from my application and when I call it from the Query Analyzer. The query plan I can only see in the Query Analyzer, if I run my query in it, so I'll never know what plan is a
ctually taken when my query runs from the application.
That's exactly my problem, I can't tune my application properly, since the queries work differently in the Query Analyzer and from my app.
By the way, to answer your questions, the plan is always the same for my query.
I also think there are some bugs in the Profiler.
My stored procedure, let's name it SP1 calls 2 other SP's, which are very fast, let's call them SP2 and SP3.
So SP1 looks something like:
...
EXEC SP2
EXEC SP3
Do some complex queries
...
In the profiler, every time I call SP1, I get 3 SP Completed events, like this (two consecutive calls, you can see the effects of the cache, which is ok):
EventClass TextData Duration
SP:Completedexec SP1 0
SP:Completedexec SP1 0
SP:Completedexec SP1 453
SP:Completedexec SP1 0
SP:Completedexec SP1 0
SP:Completedexec SP1 313
Now, I call the same SP two times from the Query Analyzer, this is what I get in the profiler:
EventClass TextData Duration
SP:Completedexec SP2 0
SP:Completedexec SP3 0
SP:Completedexec SP1 1926
SP:Completedexec SP2 0
SP:Completedexec SP3 0
SP:Completedexec SP1 2005
The profiling mechanisms seem to be different, if the SP1 is called from the Query Analyzer it looks OK, but from my app, there seems to be a bug somwhere in the event handling in the Profiler.
Any ideas?
|||I can't believe this, if I delete the proccache (dbcc freeproccache) I get almost the same response times within QA like from my application!
About 600 ms, which is much better than 2 seconds!
What can make QA generate such a bad query plan?
Another thing: my application (C++) runs as a COM object in COM+. I wrote a small C++ program which does the exact same thing (calls the same stored procedure) and this is slower than when it runs in COM+. I use ATL OLE DB to connect to the DB in both cas
es.
I can only imagine, that there must be some magic in COM+, which sets some parameters differently, thus making the SQL Server run faster/better when called from COM+.
Confusing...
|||> What can make QA generate such a bad query plan?
The cached plan may have been generated for a query that uses parameter
values that do not fall into the same distribution pattern that the later
query has. However, this is unlikely in your case since you mentioned that
they are both using the same query.
I suggest checking the execution plan from both sides. Use Profiler to
capture the execution plan, using the Show Plan Statistics event under the
Performance heading.
Regards
Ray Mond
"fmicle" <fmicle@.hotmail.com> wrote in message
news:D42860F2-6C23-48C0-AA90-9301F2697191@.microsoft.com...
> I can't believe this, if I delete the proccache (dbcc freeproccache) I get
almost the same response times within QA like from my application!
> About 600 ms, which is much better than 2 seconds!
> What can make QA generate such a bad query plan?
> Another thing: my application (C++) runs as a COM object in COM+. I wrote
a small C++ program which does the exact same thing (calls the same stored
procedure) and this is slower than when it runs in COM+. I use ATL OLE DB to
connect to the DB in both cases.
> I can only imagine, that there must be some magic in COM+, which sets some
parameters differently, thus making the SQL Server run faster/better when
called from COM+.
> Confusing...
|||No, you're right, it makes sense. When I call the SP from COM+, I use placeholders and Accessors to bind my parameters.
But I get the exact same query text in the profiler.
On the other hand, if I do the same thing outside COM+, even using the parameters, I still get the bad plan (WITH PREFETCH).
I can only reach almost the same speed outside COM+ if I delete the PROCCACHE.

Problem with Sql Query

By Running a query, I got the result set as shown below

Month Status Count
===== ====== =====
April I 129
April O 4689
April S 6
July I 131
July O 4838
July S 8
June I 131
June O 4837
June S 8
May I 131
May O 4761
May S 7

But, I need the same result set as below and no. of rows for Status is unknown. it may be more than three like (I, O, S, T, W and so on), so dynamically the there will be more columns.


Month I O S
===== = = =
April 129 4689 6
July 131 4838 8
June 131 4837 8
May 131 4761 7

Can anyone provide me the tips/solution.

Thanks in advance

RG

Reminds me of the Cross-Tab queries in MS-Access.

Check -

http://www.stephenforte.net/owdasblog/PermaLink.aspx?guid=2b0532fc-4318-4ac0-a405-15d6d813eeb8

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q175574

'Almost' dynamic column generation.

|||I believe the new pivot functionality in sql server 2005/ express will do that for ya.sql

Problem with SQL query

Hi All,
I have the following table suppliers and product.
The Supplier table have two columns Supplier_id and Supplier_name.
Below is my data in the supplier table:
Supplier_Id
Supplier_Name
2
New Orleans Cajun Delights
3
Grandma Kelly's homestead
16
Bigfoot Breweries
19
New England Seafood Cannery
5
New Mexico Seafood
4
Indian Spices
My Products table have 3 columns Product_id, Product_name and supplier_id
I have the following data in my products table:
Product_Id
Product_Name
Supplier_Id
4
Chef Anton's Cajun Seasoning
2
5
Chef Anton's Gumbo Mix
2
65
Louisiana Fiery Hot Pepper Sauce
2
66
Louisiana Hot Spice Okra
2
6
Grandma's Boysenberry Spread
3
7
Uncle Bob's Organic Dried Pears
3
8
Northwood's canaberry sauce
3
34
Sasquach Ale
16
35
Steeleye Stout
16
67
Laughing Lumberjack Lager
16
40
Boston Crab Meat
19
41
Jack's New England Clam Chowder
19
75
Chicago Pizza
NULL
22
Indian Hot Sauce
NULL
I want to find the supplier_name of the supplier who is supplying maximum
products.
Can anybody help me with the query?
Thanks,
VinitaWhy not got for the top 5-- though you can for the top 1.
SELECT top 5 supplier_name, count(*)
FROM suppliers,
product
WHERE suppliers.supplier_id = product.supplier_id
group by supplier_name
order by count(*) DESC
****************************************
***************************
Andy S.
MCSE NT/2000, MCDBA SQL 7/2000
andymcdba1@.NOMORESPAM.yahoo.com
Please remove NOMORESPAM before replying.
Always keep your antivirus and Microsoft software
up to date with the latest definitions and product updates.
Be suspicious of every email attachment, I will never send
or post anything other than the text of a http:// link nor
post the link directly to a file for downloading.
This posting is provided "as is" with no warranties
and confers no rights.
****************************************
***************************
"Vinita Sharma" <sharmavi@.mail.armstrong.edu> wrote in message
news:OnhH2Oo6DHA.1636@.TK2MSFTNGP12.phx.gbl...
quote:

> Hi All,
> I have the following table suppliers and product.
> The Supplier table have two columns Supplier_id and Supplier_name.
> Below is my data in the supplier table:
>
> Supplier_Id
> Supplier_Name
> 2
> New Orleans Cajun Delights
> 3
> Grandma Kelly's homestead
> 16
> Bigfoot Breweries
> 19
> New England Seafood Cannery
> 5
> New Mexico Seafood
> 4
> Indian Spices
>
>
> My Products table have 3 columns Product_id, Product_name and supplier_id
> I have the following data in my products table:
>
> Product_Id
> Product_Name
> Supplier_Id
> 4
> Chef Anton's Cajun Seasoning
> 2
> 5
> Chef Anton's Gumbo Mix
> 2
> 65
> Louisiana Fiery Hot Pepper Sauce
> 2
> 66
> Louisiana Hot Spice Okra
> 2
> 6
> Grandma's Boysenberry Spread
> 3
> 7
> Uncle Bob's Organic Dried Pears
> 3
> 8
> Northwood's canaberry sauce
> 3
> 34
> Sasquach Ale
> 16
> 35
> Steeleye Stout
> 16
> 67
> Laughing Lumberjack Lager
> 16
> 40
> Boston Crab Meat
> 19
> 41
> Jack's New England Clam Chowder
> 19
> 75
> Chicago Pizza
> NULL
> 22
> Indian Hot Sauce
> NULL
>
>
> I want to find the supplier_name of the supplier who is supplying maximum
> products.
> Can anybody help me with the query?
> Thanks,
> Vinita
>
|||Thanks a zillion.
It worked
"Andy Svendsen" <andymcdba1@.NOMORESPAM.yahoo.com> wrote in message
news:uin4tno6DHA.2496@.TK2MSFTNGP09.phx.gbl...
> Why not got for the top 5-- though you can for the top 1.
> SELECT top 5 supplier_name, count(*)
> FROM suppliers,
> product
> WHERE suppliers.supplier_id = product.supplier_id
> group by supplier_name
> order by count(*) DESC
> --
> ****************************************
***************************
> Andy S.
> MCSE NT/2000, MCDBA SQL 7/2000
> andymcdba1@.NOMORESPAM.yahoo.com
> Please remove NOMORESPAM before replying.
> Always keep your antivirus and Microsoft software
> up to date with the latest definitions and product updates.
> Be suspicious of every email attachment, I will never send
> or post anything other than the text of a http:// link nor
> post the link directly to a file for downloading.
> This posting is provided "as is" with no warranties
> and confers no rights.
> ****************************************
***************************
> "Vinita Sharma" <sharmavi@.mail.armstrong.edu> wrote in message
> news:OnhH2Oo6DHA.1636@.TK2MSFTNGP12.phx.gbl...
supplier_id
maximum
>

Problem with SQL Notification - cannot find a non-existant user

I am having the following error trying to get a SQL Notification to work. I have followed the "Creating a Query for Notification" at http://msdn2.microsoft.com/en-us/library/ms181122.aspx, but so far without success in resolving this.

Source:
.Net SqlClient Data Provider
Data:
System.Collections.ListDictionaryInternal
Message:
Cannot find the user 'owner', because it does not exist or you do not have permission.
Cannot find the queue 'SqlQueryNotificationService--guid deleted--',
because it does not exist or you do not have permission.
Invalid object name 'SqlQueryNotificationService--guid deleted--'.
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at SqlDependencyProcessDispatcher.SqlConnectionContainer.CreateQueueAndService(Boolean restart)
at SqlDependencyProcessDispatcher.SqlConnectionContainer..ctor(SqlConnectionContainerHashHelper hashHelper, String appDomainKey, Boolean useDefaults)
at SqlDependencyProcessDispatcher.Start(String connectionString, String& server, DbConnectionPoolIdentity& identity, String& user, String& database, String& queueService, String appDomainKey, SqlDependencyPerAppDomainDispatcher dispatcher, Boolean& errorOccurred, Boolean& appDomainStart, Boolean useDefaults)By changing the service logon account from a local one to a domain account I have stopped the above error.

problem with sql

I've been having problems with the following query. It falls over on the first BEGIN but I can't se why.

Any sugguestions?

Set transaction isolation level read uncommitted

Declare @.Date DateTime
Declare @.Msg VarChar(255)
set @.Date = Getdate()-44

If (Select z.lastamendedby from dbo.intray as z
Where z.lastamendedby in
(select x.userid from dbo.useractivity as x left join dbo.users as y on x.userid = y.user_id
where x.lastactivityTime < @.Date))
--and y.ntSuspended = 0)
--and z.lastamended > @.Date
Begin

set @.Msg = "These users have done work since the 44 day period, don't suspend"
Print @.Msg
End


Else

Begin
Select z.lastamendedby from dbo.intray as z
Where lastamendedby in
(select x.userid from dbo.useractivity as x left join dbo.users as y on x.userid = y.user_id
where x.lastactivityTime < @.Date
and y.ntSuspended = 0)
Set @.Msg = "These users haven't done any work since the 44 day period, suspend"
Print @.Msg

End

Cheers,

Jim

Because you didn't finish your IF.

If you reduce it down, maybe you'll see:

IF (SELECT lastamendedby)
BEGIN

Just out of curiosity, what company do you work for? Cause I'm definately interested in finding one that only suspends you if you haven't done anything for 44 days ;-p

Friday, March 23, 2012

Problem with sp_grantdbaccess

When the I execute the following back to back in the SQL Query Analyzer,
I get an error:
Line 2: Incorrect syntax near 'sp_grantdbaccess'.
sp_revokedbaccess auser;
sp_grantdbaccess auser;
However, when I execute them individually, they work fine. Where's the
syntax error?
Or is there a better way remove a user as db_owner but still grant them
access to the database?
The two commands need to be executed in separate batches. So the syntax
should be:
sp_revokedbaccess auser
go
sp_grantdbaccess auser
However, it appears that you just want to remove a user from the 'db_owner'
role. So following command should do your work:
EXEC sp_droprolemember 'db_owner', 'YourUserName'
"O.B." wrote:

> When the I execute the following back to back in the SQL Query Analyzer,
> I get an error:
> Line 2: Incorrect syntax near 'sp_grantdbaccess'.
> sp_revokedbaccess auser;
> sp_grantdbaccess auser;
> However, when I execute them individually, they work fine. Where's the
> syntax error?
> Or is there a better way remove a user as db_owner but still grant them
> access to the database?
|||If a call to a stored procedure is not the first thing in a batch, you must
use the word EXECUTE (or EXEC).
So you can either separate the two calls into separate batches:
sp_revokedbaccess auser;
go
sp_grantdbaccess auser;
go
OR
you can use EXEC:
sp_revokedbaccess auser;
EXEC sp_grantdbaccess auser;
You might want to consider always using EXEC to call a procedure, then you
never need to worry about whether it's the first thing in the batch or not.
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"O.B." <funkjunk@.bellsouth.net> wrote in message
news:11om94vm6grltd3@.corp.supernews.com...
> When the I execute the following back to back in the SQL Query Analyzer, I
> get an error:
> Line 2: Incorrect syntax near 'sp_grantdbaccess'.
> sp_revokedbaccess auser;
> sp_grantdbaccess auser;
> However, when I execute them individually, they work fine. Where's the
> syntax error?
> Or is there a better way remove a user as db_owner but still grant them
> access to the database?
>
sql

Problem with sp_grantdbaccess

When the I execute the following back to back in the SQL Query Analyzer,
I get an error:
Line 2: Incorrect syntax near 'sp_grantdbaccess'.
sp_revokedbaccess auser;
sp_grantdbaccess auser;
However, when I execute them individually, they work fine. Where's the
syntax error?
Or is there a better way remove a user as db_owner but still grant them
access to the database?The two commands need to be executed in separate batches. So the syntax
should be:
sp_revokedbaccess auser
go
sp_grantdbaccess auser
However, it appears that you just want to remove a user from the 'db_owner'
role. So following command should do your work:
EXEC sp_droprolemember 'db_owner', 'YourUserName'
"O.B." wrote:
> When the I execute the following back to back in the SQL Query Analyzer,
> I get an error:
> Line 2: Incorrect syntax near 'sp_grantdbaccess'.
> sp_revokedbaccess auser;
> sp_grantdbaccess auser;
> However, when I execute them individually, they work fine. Where's the
> syntax error?
> Or is there a better way remove a user as db_owner but still grant them
> access to the database?|||If a call to a stored procedure is not the first thing in a batch, you must
use the word EXECUTE (or EXEC).
So you can either separate the two calls into separate batches:
sp_revokedbaccess auser;
go
sp_grantdbaccess auser;
go
OR
you can use EXEC:
sp_revokedbaccess auser;
EXEC sp_grantdbaccess auser;
You might want to consider always using EXEC to call a procedure, then you
never need to worry about whether it's the first thing in the batch or not.
--
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"O.B." <funkjunk@.bellsouth.net> wrote in message
news:11om94vm6grltd3@.corp.supernews.com...
> When the I execute the following back to back in the SQL Query Analyzer, I
> get an error:
> Line 2: Incorrect syntax near 'sp_grantdbaccess'.
> sp_revokedbaccess auser;
> sp_grantdbaccess auser;
> However, when I execute them individually, they work fine. Where's the
> syntax error?
> Or is there a better way remove a user as db_owner but still grant them
> access to the database?
>

Problem with sp_grantdbaccess

When the I execute the following back to back in the SQL Query Analyzer,
I get an error:
Line 2: Incorrect syntax near 'sp_grantdbaccess'.
sp_revokedbaccess auser;
sp_grantdbaccess auser;
However, when I execute them individually, they work fine. Where's the
syntax error?
Or is there a better way remove a user as db_owner but still grant them
access to the database?The two commands need to be executed in separate batches. So the syntax
should be:
sp_revokedbaccess auser
go
sp_grantdbaccess auser
However, it appears that you just want to remove a user from the 'db_owner'
role. So following command should do your work:
EXEC sp_droprolemember 'db_owner', 'YourUserName'
"O.B." wrote:

> When the I execute the following back to back in the SQL Query Analyzer,
> I get an error:
> Line 2: Incorrect syntax near 'sp_grantdbaccess'.
> sp_revokedbaccess auser;
> sp_grantdbaccess auser;
> However, when I execute them individually, they work fine. Where's the
> syntax error?
> Or is there a better way remove a user as db_owner but still grant them
> access to the database?|||If a call to a stored procedure is not the first thing in a batch, you must
use the word EXECUTE (or EXEC).
So you can either separate the two calls into separate batches:
sp_revokedbaccess auser;
go
sp_grantdbaccess auser;
go
OR
you can use EXEC:
sp_revokedbaccess auser;
EXEC sp_grantdbaccess auser;
You might want to consider always using EXEC to call a procedure, then you
never need to worry about whether it's the first thing in the batch or not.
--
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"O.B." <funkjunk@.bellsouth.net> wrote in message
news:11om94vm6grltd3@.corp.supernews.com...
> When the I execute the following back to back in the SQL Query Analyzer, I
> get an error:
> Line 2: Incorrect syntax near 'sp_grantdbaccess'.
> sp_revokedbaccess auser;
> sp_grantdbaccess auser;
> However, when I execute them individually, they work fine. Where's the
> syntax error?
> Or is there a better way remove a user as db_owner but still grant them
> access to the database?
>

Problem with sp_executesql

I try to write query that use sp_executesql to query data by Like operation with 1 parameter like below:
execute sp_executesql N'SELECT DISTINCT au_id,
au_lname,au_fname
FROM authors
WHERE au_lname LIKE @.au_lname
',
N'@.au_lname nVarChar',
@.au_lname = N'%Cas%'

but It return all rows regardless of changing condition to any value.

But if i don't use sp_executesql like below:

SELECT DISTINCT au_id,
au_lname,au_fname
FROM authors
WHERE au_lname LIKE N'%Cas%'

It's correct!

Can anyone tell me why?

ThanksChange your code as follows:

N'@.au_lname nVarChar', -->>> N'@.au_lname nVarChar(5)',|||Thank you very much for feedback!

Wednesday, March 21, 2012

Problem with simple subquery in SQL2005 AND SQL2000.

When I use the simple query with a subquery shown below, this is the error message I get in SQL 2000 AND SQL 2005

"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."

And here is the query I use:

SELECT docSections.SectionID,

(SELECT docSectionText.colText FROM docSectionText

WHERE (docSections.SectionID = docSectionText.SectionID)

AND (docSectionText.colOrdinal = 1)) AS SecTitle

FROM docSections

Can anyone please let me know what I do wrong here.

Thanks

Gerhard

I can tell you why you get the error. But, without understanding your schema and requirements, I can not give you a solution for what you are trying to do.

The problem is that when you have a subquery in your SELECT it can only return 1 row per row. So, your subquery must be returning multiple rows.

To check try the following queries and see what it returns.

-- This should show you the sectionid that have multiple rows with colOrdinal = 1
SELECT SECTIONID, count(coltext) as rowcount
FROM docSections
WHERE docSectionText.colOrdinal = 1
GROUP BY SectionID
HAVING count(coltext) > 1

-- This should checks if perhaps the identified sections have multiple rows
--but all with same coltext. If first returns rows, but this doesn't,
--then you can add distinct to solve your problems
SELECT SECTIONID, count(distinct coltext) as rowcount
FROM docSections
WHERE docSectionText.colOrdinal = 1
GROUP BY SectionID
HAVING count(distinct coltext) > 1

HTH

|||

Thank You very much.

You were correct. I had 2 doubles in my table.

Gerhard

Problem with simple SQL


I want to view all companyname that starts with A, the sql runs but does not show the output,
What's wrong with the query?, am I missing any quotes or comma. Pls 'elp
Dim myCharacter = "A"
SQL = "SELECTlogo, EmployerID, CompanyName FROM EmployerDetails wherecompanyName like '"&myCharacter & "%'"



Select seems correct! How you are using this in ASP.NET page? Are you getting data into Reader or not?|||Thanks Sreed
I think the problem is the SQL because when I hard code to this
SQL = "SELECT logo, EmployerID, CompanyName FROM EmployerDetails where companyName like 'A%' "
It works, PLS help Thanks
|||

If you declared myCharacter,SQL as a local string variable, then it should work!

Just to debug after SQL = "..blabla" statement do,

Response.Write(SQL)
Response.End()
and run the page and see what is the output you are getting from SQL, and see if that is giving correct Select or not!

That should help us to find whether it building currect SQL or not!

|||Hi Sreed
This is the full code below , I did the PRINT STUFF and the output is also below
Sub BindDataToGrid(myCharacter)
Response.write("Testing "&myCharacter)
Dim Conn, Conn1 as SqlConnection
Dim mySqlCommand, mySqlCommand2 as SqlCommand
Dim SQL,SQL1,SQL2 ,GetQuestions As String
Dim myDate as date
Dim pic as ArrayList = new ArrayList()
Dim Job_no as Integer

IF myCharacter <> "" THEN
SQL ="SELECT logo, EmployerID, CompanyName FROM EmployerDetails where companyName like "
SQL = SQL & " ' " & myCharacter & " % ' "
Else
SQL ="SELECT logo, EmployerID FROM EmployerDetails order by newID() "
End If
Conn = New SqlConnection(ConfigurationSettings.AppSettings("connString"))
Dim resultsDataSet as New DataSet()
Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(SQL, Conn)

Conn.Open()
myDataAdapter.Fill(resultsDataSet,"EmployerDetails")
mySqlCommand = New SqlCommand(SQL, Conn)
mySqlCommand.ExecuteNonQuery()

Dim myReader As SqlDataReader = mysqlCommand.ExecuteReader()
Dim content
While myReader.Read()
If not (myReader("Logo") is DBNull.Value) Then
If Len(myReader("Logo")) > 0 Then
Dim LOGO = myReader("Logo")
Dim EmployerID =myReader("EmployerID")
Content = "<br><ahref='/JBoard/EmployerJobs.aspx?EMPID="&EmployerID
Content = Content & " '><img src='/JBoard/CompLogo/"&Logo
Content = Content & " ' width='124' height='50'BORDER='1'></a>"
pic.Add(Content)
End If
End If
End While

LogoGrid.DataSource = pic
LogoGrid.DataBind()
Conn.Close()
End Sub

OUTPUT IS
SELECT logo, EmployerID, CompanyName FROM EmployerDetails where companyName like 'M % '
What is wrong with this tiny code, forum help me pls.


|||

SQL = "SELECT logo, EmployerID, CompanyName FROM EmployerDetails where companyName like "
SQL = SQL &" ' " & myCharacter &" % ' "

This looks like you have extra spaces in there. If you copied and pasted this directly from your code, you're actually querying for anything that starts with a space and then an 'A' and then has a space and then any character and then a space. Drop the spaces in theRED code above and it should work.

|||Hi PD
How do you drop the space, that's why I thought ?

|||Use your keyboard's Delete key to remove the extra spaces around thesingle quote and percentage characters. (A total of 4 spacesshould be deleted.)
That should leave you with the following statement:
SQL = "SELECT logo, EmployerID, CompanyName FROM EmployerDetails where companyName like "
SQL = SQL &"'" & myCharacter &"%' "
|||

tmorton wrote:

Use your keyboard's Delete key to remove the extra spaces


In a recent technical journal, it suggested that the Backspace key canalso be used to remove characters. I haven't tried it myself, as I fearthat I'm not advanced enough. But obinna123 seems pretty advanced, sohe may want to try that technique to removed the extra spaces.