显示标签为“procedure”的博文。显示所有博文
显示标签为“procedure”的博文。显示所有博文

2012年3月29日星期四

display a message in store procedure

 helo all..., this is my store procedure. but it can not display message. my friend said it must use output code.
can someone add output code to my store procedure, so it can display message?

ALTER PROCEDURE [bank].[dbo].[pay]
(
@.no_billINT,
@.no_orderint,
@.totalcostmoney,
@.messagevarchar(100)-- make it output parameter in your stored procedure
)
AS

BEGIN TRANSACTION

DECLARE @.balanceAS money

select @.balance = balance
from bank.dbo.bill
where no_bill = @.no_bill

select @.totalcost = totalcost
from games.dbo.totalcost
where no_order = @.no_order

if (@.balance > @.totalcost)
begin
set @.balance = @.balance - @.totalcost

UPDATE bank.dbo.bill
SET
[balance] = @.balance
WHERE [no_bill] = @.no_bill

-- set @.message = 'your have enough balance'
end
else
begin
set @.message ='sorry, your balance not enough'
end

COMMIT TRANSACTION

set nocount off

 
 
pls.., thx 

ALTER PROCEDURE [bank].[dbo].[pay]( @.no_billINT, @.no_orderint, @.totalcostmoney, @.messagevarchar(100)OUTPUT-- make it output parameter in your stored procedure)ASBEGIN TRANSACTION DECLARE @.balanceAS moneyselect @.balance = balancefrom bank.dbo.billwhere no_bill = @.no_billselect @.totalcost = totalcostfrom games.dbo.totalcostwhere no_order = @.no_orderif (@.balance > @.totalcost)beginset @.balance = @.balance - @.totalcostUPDATE bank.dbo.billSET [balance] = @.balanceWHERE [no_bill] = @.no_billset @.message ='your have enough balance'endelsebeginset @.message ='sorry, your balance not enough'end

|||

yes, thx. but when i execute that procedure, it told to insert no_order, no_bill,totalcost, message. i don't want to insert message, i want to insert no_order,no_bill,totalcost, and click ok, so then message automatic display it..

can u add any code ?

thx...

|||

Using the code posted below, I dont see how it could be wanting to "INSERT" or "UPDATE" message. We are setting the parameter @.message after the update statement is completed.
If you are still getting the error then post the current version of the code you are using.

ALTER PROCEDURE [bank].[dbo].[pay]( @.no_billINT, @.no_orderint, @.totalcostmoney, @.messagevarchar(100)OUTPUT-- make it output parameter in your stored procedure)ASBEGIN TRANSACTION DECLARE @.balanceAS money select @.balance = balancefrom bank.dbo.billwhere no_bill = @.no_billselect @.totalcost = totalcostfrom games.dbo.totalcostwhere no_order = @.no_orderif (@.balance > @.totalcost)begin set @.balance = @.balance - @.totalcostUPDATE bank.dbo.billSET [balance] = @.balanceWHERE [no_bill] = @.no_billset @.message ='your have enough balance'end else begin set @.message ='sorry, your balance not enough'endCOMMIT TRANSACTION
|||

yes, your code are right, but when i execute your code, it display:

type direction name value

int in no_bill we insert to this,example:110

int in no_order we insert to this,ex:2

money in totalcost we insert to this, ex 100$

char in/out message ??? if i not insert to this, myerror :Procedure or Function 'pay' expects parameter '@.message', whichwas not supplied.

so i must insert it something, then it can work... but i want to only insert no_bill,no_order,totalcost,so message is display automatic after i insert no_bill,no_order,totalcost.. is there can show automatic message without insert data to message?

thx...

|||

When you define an output parameter in a Stored procedure, you still need to pass a parameter in to the stored procedure. In your case you would pass in an empty string param.

Its not inserting into your DB message it just needs to know what to pass your output param back to.

If you need help with calling the stored procedure, then post that code where you are calling it and we can help you call it properly.

|||

thx .., now i want to call that message from pay.aspx. this is my pay.aspx.vb like:

pay.aspx.vb

Protected Sub Button1_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs) Handles Button1.Command

Dim sp As String = "pay"
Dim connect As String = ConfigurationManager.AppSettings("ConnectionString")
Dim conn As New SqlConnection(connect)
Dim cm As New SqlCommand(sp, conn)
Dim totalcost As Label = Me.FormView1.FindControl("totallabel")
Dim no As Label = Me.FormView1.FindControl("no_orderlabel")
cm.CommandType = CommandType.StoredProcedure
cm.Parameters.AddWithValue("@.totalcost ", totalcost.Text)
cm.Parameters.AddWithValue("@.no_order ", no.Text)
cm.Parameters.AddWithValue("@.no_bill ", no_bill.Text)
cm.Parameters.AddWithValue("@.message", Label1.Text )

conn.Open()
cm.ExecuteNonQuery() ' do not forget to close Connection
conn.Close()

end sub

that code can work..., but i don't know about to display that message.

if totalcost > balance, show message"sorry, your balance is not enough"

if totalcost<balance, not show message..

pls...

thx...


|||

First change

cm.Parameters.AddWithValue("@.message", Label1.Text )

to

cm.Parameters.Add(New SqlParameter("@.message", SqlDbType.VarChar, 250, ParameterDirection.Output))

Then right after

cm.ExecuteNonQuery() ' do not forget to close Connection

add

Dim message As String - cm.Parameters("@.message").Value

|||

thx, it work.. but not display a message.

so i put label1.text in this, but it still no display a message. this is my code:

Protected Sub Button1_Command(ByVal sender As Object, ByVal e AsSystem.Web.UI.WebControls.CommandEventArgs) Handles Button1.Command

Dim sp As String = "pay"
Dim connect As String = ConfigurationManager.AppSettings("ConnectionString")
Dim conn As New SqlConnection(connect)
Dim cm As New SqlCommand(sp, conn)
Dim totalcost As Label = Me.FormView1.FindControl("totallabel")
Dim no As Label = Me.FormView1.FindControl("no_orderlabel")
cm.CommandType = CommandType.StoredProcedure
cm.Parameters.AddWithValue("@.totalcost ", totalcost.Text)
cm.Parameters.AddWithValue("@.no_order ", no.Text)
cm.Parameters.AddWithValue("@.no_bill ", no_bill.Text)
cm.Parameters.Add(New SqlParameter("@.message", SqlDbType.VarChar, 250, ParameterDirection.Output))

conn.Open()
cm.ExecuteNonQuery() ' do not forget to close Connection

Dim message As String - cm.Parameters("@.message").Value
conn.Close()
label1.text= message

end sub

but the label no show message.. how should i do?

thx...

|||

have you tried debugging and stepping through the code?

|||

yes, i have many try it, but not show a message, maybe i put label1.text in wrong location. can u show that label put in true location?

pls..,thx..

|||

other than changing it to

label1.text = message.tostring()

your code looks correct. When you step through it set a breakpoing on "Dim message as string" so when you step on to conn.close() you can see if message has a value.

|||

i have use breakpoint at row label1.text, it display value text="". it mean not take message from @.message,so empty..

or maybe my store procedure is wrong?

this is my store procedure

ALTER PROCEDURE [bank].[dbo].[paid]
(
@.no_billINT,
@.no_orderint,
@.totalcostmoney,
@.messagevarchar(100) output="a"
)
AS

BEGIN TRANSACTION

DECLARE @.balanceAS money

select @.balance = balance
from bank.dbo.bill
where no_bill = @.no_bill

select @.totalcost = totalcost
from games.dbo.totalcost
where no_order = @.no_order

if (@.balance > @.totalcost)
begin
set @.balance = @.balance - @.totalcost

UPDATE bank.dbo.bill
SET
[balance] = @.balance
WHERE [no_bill] = @.no_bill

-- set @.message = 'your have enough balance'
end
else
begin
set @.message ='sorry, your balance not enough'
end

COMMIT TRANSACTION

but i execute in store procedure, it can display message...
so,which is wrong?
thx 

|||

Here is an article for you on another way to define an output parameter.

http://www.sqlservercentral.com/columnists/kKellenberger/usingparameterswithstoredprocedures.asp

Also you have in your stored procedure one line commented out that sets @.message, and your also trying to set a default value using double quotes.

If you want to set a default value for the parameter then set it inside of your begin transaction statement, and also use single quotes in setting it.

2012年3月27日星期二

Disk space information in SQL Server 2005.

As a normal sql user we are not able to get the disk space information by

executing 'xp_fixeddrive' extended stored procedure.

We are able to get the result using sa user and windows authenticated user.

Any help will be appreciated.

You may get the information you seek by querying: sys.sysfiles,

or perhaps using the dynamic management view: sys.dm_db_file_space_usage

Refer to Books Online for more information about either of them.

|||the xp_fixeddrives can get the free space in the disk(drivers). it is different to sys.sysfiles.

|||do you have the permission to run this extend procedure? any error informaiton that you got when you used a normall sql user?

I think it caused by the permission. .when you login as sa or windows administrator account , it belongs to sysadmin group by default.

2012年3月20日星期二

Disconnection when 'xp_cmd' is in a comment

If I run the following in Query Analyzer against Microsoft SQL Server
2000 - 8.00.818 while logged in as 'sa':
ALTER PROCEDURE __Test AS
BEGIN
/*
-- x p_cmd
*/
RETURN 0
END
GO
then all is well, but if I remove the space between the 'x' and the
'p' in the comment line then I get the following error:
[Microsoft][ODBC SQL Server Driver][TCP/IP
Sockets]ConnectionCheckForData (CheckforData()).
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation.
ODBC: Msg 0, Level 16, State 1
Communication link failure
ODBC: Msg 0, Level 16, State 1
Communication link failure
Connection Broken
I am connecting remotely. Another user who is on the same domain as
the server does not have this problem. I assume some hardware or
software on the connection between the server and myself and the
server is causing the problem.
Does anyone have any idea what this could be?
Thanks
SylvesterIf it's hardware or software connectivity between you and
the server then you'd likely find something in the windows
event logs so you may want to start checking those.
-Sue
On 10 Oct 2004 22:01:39 -0700, junk@.riddell.co.nz
(Sylvester) wrote:

>If I run the following in Query Analyzer against Microsoft SQL Server
>2000 - 8.00.818 while logged in as 'sa':
>
> ALTER PROCEDURE __Test AS
> BEGIN
> /*
> -- x p_cmd
> */
> RETURN 0
> END
> GO
>then all is well, but if I remove the space between the 'x' and the
>'p' in the comment line then I get the following error:
> [Microsoft][ODBC SQL Server Driver][TCP/IP
>Sockets]ConnectionCheckForData (CheckforData()).
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation.
> ODBC: Msg 0, Level 16, State 1
> Communication link failure
> ODBC: Msg 0, Level 16, State 1
> Communication link failure
> Connection Broken
>
>I am connecting remotely. Another user who is on the same domain as
>the server does not have this problem. I assume some hardware or
>software on the connection between the server and myself and the
>server is causing the problem.
>Does anyone have any idea what this could be?
>Thanks
>Sylvester

Disconnection when 'xp_cmd' is in a comment

If I run the following in Query Analyzer against Microsoft SQL Server
2000 - 8.00.818 while logged in as 'sa':
ALTER PROCEDURE __Test AS
BEGIN
/*
-- x p_cmd
*/
RETURN 0
END
GO
then all is well, but if I remove the space between the 'x' and the
'p' in the comment line then I get the following error:
[Microsoft][ODBC SQL Server Driver][TCP/IP
Sockets]ConnectionCheckForData (CheckforData()).
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation.
ODBC: Msg 0, Level 16, State 1
Communication link failure
ODBC: Msg 0, Level 16, State 1
Communication link failure
Connection Broken
I am connecting remotely. Another user who is on the same domain as
the server does not have this problem. I assume some hardware or
software on the connection between the server and myself and the
server is causing the problem.
Does anyone have any idea what this could be?
Thanks
Sylvester
If it's hardware or software connectivity between you and
the server then you'd likely find something in the windows
event logs so you may want to start checking those.
-Sue
On 10 Oct 2004 22:01:39 -0700, junk@.riddell.co.nz
(Sylvester) wrote:

>If I run the following in Query Analyzer against Microsoft SQL Server
>2000 - 8.00.818 while logged in as 'sa':
>
> ALTER PROCEDURE __Test AS
> BEGIN
> /*
> -- x p_cmd
> */
>RETURN 0
> END
> GO
>then all is well, but if I remove the space between the 'x' and the
>'p' in the comment line then I get the following error:
> [Microsoft][ODBC SQL Server Driver][TCP/IP
>Sockets]ConnectionCheckForData (CheckforData()).
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation.
> ODBC: Msg 0, Level 16, State 1
> Communication link failure
> ODBC: Msg 0, Level 16, State 1
> Communication link failure
> Connection Broken
>
>I am connecting remotely. Another user who is on the same domain as
>the server does not have this problem. I assume some hardware or
>software on the connection between the server and myself and the
>server is causing the problem.
>Does anyone have any idea what this could be?
>Thanks
>Sylvester

Disconnection when 'xp_cmd' is in a comment

If I run the following in Query Analyzer against Microsoft SQL Server
2000 - 8.00.818 while logged in as 'sa':
ALTER PROCEDURE __Test AS
BEGIN
/*
-- x p_cmd
*/
RETURN 0
END
GO
then all is well, but if I remove the space between the 'x' and the
'p' in the comment line then I get the following error:
[Microsoft][ODBC SQL Server Driver][TCP/IP
Sockets]ConnectionCheckForData (CheckforData()).
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation.
ODBC: Msg 0, Level 16, State 1
Communication link failure
ODBC: Msg 0, Level 16, State 1
Communication link failure
Connection Broken
I am connecting remotely. Another user who is on the same domain as
the server does not have this problem. I assume some hardware or
software on the connection between the server and myself and the
server is causing the problem.
Does anyone have any idea what this could be?
Thanks
SylvesterIf it's hardware or software connectivity between you and
the server then you'd likely find something in the windows
event logs so you may want to start checking those.
-Sue
On 10 Oct 2004 22:01:39 -0700, junk@.riddell.co.nz
(Sylvester) wrote:
>If I run the following in Query Analyzer against Microsoft SQL Server
>2000 - 8.00.818 while logged in as 'sa':
>
> ALTER PROCEDURE __Test AS
> BEGIN
> /*
> -- x p_cmd
> */
> RETURN 0
> END
> GO
>then all is well, but if I remove the space between the 'x' and the
>'p' in the comment line then I get the following error:
> [Microsoft][ODBC SQL Server Driver][TCP/IP
>Sockets]ConnectionCheckForData (CheckforData()).
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation.
> ODBC: Msg 0, Level 16, State 1
> Communication link failure
> ODBC: Msg 0, Level 16, State 1
> Communication link failure
> Connection Broken
>
>I am connecting remotely. Another user who is on the same domain as
>the server does not have this problem. I assume some hardware or
>software on the connection between the server and myself and the
>server is causing the problem.
>Does anyone have any idea what this could be?
>Thanks
>Sylvester

2012年3月19日星期一

disconnect users

Hi,
I was wondering if there is a stored procedure that could disconnect users.
I have job which does some integrity checks, but for one database it
always fails. There is always a connection open. That particular
useraccount is for the oracle applicationserver which should remain active.
How can i resolve this matter and still do maintenance?Do you want to disconnect the users, or not disconnect that user?
If you want to disconnect the users:
USE <databasename>
GO
ALTER DATABASE <databasename> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
(note, this will force all users out and cause any transactions they're in
to roll back -- immediately. There is also a time option; look up syntax in
BOL.)
To allow other users to connect once you're done:
ALTER DATABASE <databasename> SET MULTI_USER
GO
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"Jason" <jasonlewis@.hotmail.com> wrote in message
news:%23Qqt7rkeGHA.4912@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I was wondering if there is a stored procedure that could disconnect
> users.
> I have job which does some integrity checks, but for one database it
> always fails. There is always a connection open. That particular
> useraccount is for the oracle applicationserver which should remain
> active.
> How can i resolve this matter and still do maintenance?

disconnect users

Hi,
I was wondering if there is a stored procedure that could disconnect users.
I have job which does some integrity checks, but for one database it
always fails. There is always a connection open. That particular
useraccount is for the oracle applicationserver which should remain active.
How can i resolve this matter and still do maintenance?Do you want to disconnect the users, or not disconnect that user?
If you want to disconnect the users:
USE <databasename>
GO
ALTER DATABASE <databasename> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
(note, this will force all users out and cause any transactions they're in
to roll back -- immediately. There is also a time option; look up syntax in
BOL.)
To allow other users to connect once you're done:
ALTER DATABASE <databasename> SET MULTI_USER
GO
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"Jason" <jasonlewis@.hotmail.com> wrote in message
news:%23Qqt7rkeGHA.4912@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I was wondering if there is a stored procedure that could disconnect
> users.
> I have job which does some integrity checks, but for one database it
> always fails. There is always a connection open. That particular
> useraccount is for the oracle applicationserver which should remain
> active.
> How can i resolve this matter and still do maintenance?

2012年3月7日星期三

Disappearing Linked Server Stored Procedures

When I create a stored procedure like the one below and save it,
everything seems fine. But when I close Enterprise Manager and
re-open it, the stored procedure is gone.

Any ideas?

SET ANSI_DEFAULTS ON
GO
CREATE PROCEDURE [dbo].[sp_Test] AS
SELECT * FROM OPENQUERY(LINKEDSERVER, 'SELECT V.VENDOR_ID,
V.VENDOR_NAME FROM VENDOR V')
GO

Ted"Ted Calhoon" <tedcalhoon@.hotmail.com> wrote in message
news:fc57c4d8.0312121455.1e0677d8@.posting.google.c om...
> When I create a stored procedure like the one below and save it,
> everything seems fine. But when I close Enterprise Manager and
> re-open it, the stored procedure is gone.
> Any ideas?
>
> SET ANSI_DEFAULTS ON
> GO
> CREATE PROCEDURE [dbo].[sp_Test] AS
> SELECT * FROM OPENQUERY(LINKEDSERVER, 'SELECT V.VENDOR_ID,
> V.VENDOR_NAME FROM VENDOR V')
> GO
>
> Ted

If you put only the CREATE PROCEDURE statement into the create procedure
dialogue, it will work:

CREATE PROCEDURE [dbo].[sp_Test] AS
SELECT * FROM OPENQUERY(LINKEDSERVER, 'SELECT V.VENDOR_ID,
V.VENDOR_NAME FROM VENDOR V')

Presumably, this is a 'feature' in EM, which seems to have a number of
quirks. If you need full control over the CREATE PROC statement, you should
execute it in Query Analyzer instead, which is probably a better practice in
general.

Also, don't use sp_ as a procedure name prefix, that's reserved for system
stored procedures.

Simon|||Thanks, Simon. I will take your advice and:

1. Use Query Analyzer to create stored procedures
2. Avoid using sp_ when naming my stored procedures

Ted

Disabling triggers from stored procedures

Hi,
Is it possible to disable a trigger from a Stored Procedure? If it is, how do you do it?
Thanks,
FedericoALTER TABLE [MyTable] DISABLE TRIGGER trMyTrigger|||Just curious as to why you would want to do this?|||Yes, it is possible to disable the trigger, but keep in mind that you are disabling that trigger for everyone using the table, not just for what the trigger is doing. I don't know of any way to allow a trigger to function for some users/spids and not for others, except to include code within the trigger to make it decide that it shouldn't run under some conditions.

-PatP|||If SQL Server 2000 and one can alter the trigger then one can use SET CONTEXT_INFO in SP and then check master..sysprocesses from trigger.

Might also insert DBCC INPUTBUFFER(@.@.SPID) results into temporary table in trigger to check for proc name in EventInfo column. Would work in SQL Server 7 and would not require any additional code in SP, but would hurt trigger performance, be kludgy, and require hard-coding proc name(s) in trigger.

2012年2月24日星期五

Disable/Enable Triggers

I have stored procedure that disable triggers from another table then
completes the
body for the stored procedures then enables the triggers.
Is there an easy way to complete this task of disable and enable triggers
with very little overhead.
Thank You,
On Thu, 3 Nov 2005 14:30:03 -0800, Joe K. <Joe
K.@.discussions.microsoft.com> wrote:

>I have stored procedure that disable triggers from another table then
>completes the
>body for the stored procedures then enables the triggers.
>Is there an easy way to complete this task of disable and enable triggers
>with very little overhead.
>Thank You,
Hi Joe,
The good news: look up
ALTER TABLE table
{ ENABLE | DISABLE } TRIGGER { ALL | trigger_name [,..n] }
in Books Online.
The bad news: this is not a per-connection setting. If you disable the
trigger, it won't fire for ANY connection that's accessing the table.
Unless you can be sure that the stored proc is the only active process
at the time, I'd urge you to find another way to achieve what you want.
If you post more information about what business problem you're trying
to solve, we can help you find a better way.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

Disable/Enable Triggers

I have stored procedure that disable triggers from another table then
completes the
body for the stored procedures then enables the triggers.
Is there an easy way to complete this task of disable and enable triggers
with very little overhead.
Thank You,On Thu, 3 Nov 2005 14:30:03 -0800, Joe K. <Joe
K.@.discussions.microsoft.com> wrote:
>I have stored procedure that disable triggers from another table then
>completes the
>body for the stored procedures then enables the triggers.
>Is there an easy way to complete this task of disable and enable triggers
>with very little overhead.
>Thank You,
Hi Joe,
The good news: look up
ALTER TABLE table
{ ENABLE | DISABLE } TRIGGER { ALL | trigger_name [,..n] }
in Books Online.
The bad news: this is not a per-connection setting. If you disable the
trigger, it won't fire for ANY connection that's accessing the table.
Unless you can be sure that the stored proc is the only active process
at the time, I'd urge you to find another way to achieve what you want.
If you post more information about what business problem you're trying
to solve, we can help you find a better way.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Disable/Enable Triggers

I have stored procedure that disable triggers from another table then
completes the
body for the stored procedures then enables the triggers.
Is there an easy way to complete this task of disable and enable triggers
with very little overhead.
Thank You,On Thu, 3 Nov 2005 14:30:03 -0800, Joe K. <Joe
K.@.discussions.microsoft.com> wrote:

>I have stored procedure that disable triggers from another table then
>completes the
>body for the stored procedures then enables the triggers.
>Is there an easy way to complete this task of disable and enable triggers
>with very little overhead.
>Thank You,
Hi Joe,
The good news: look up
ALTER TABLE table
{ ENABLE | DISABLE } TRIGGER { ALL | trigger_name [,..n] }
in Books Online.
The bad news: this is not a per-connection setting. If you disable the
trigger, it won't fire for ANY connection that's accessing the table.
Unless you can be sure that the stored proc is the only active process
at the time, I'd urge you to find another way to achieve what you want.
If you post more information about what business problem you're trying
to solve, we can help you find a better way.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Disable Triggers (using alter with public)

Hey folks,

Here's the skinny
I'm trying to run a stored procedure that requires triggers to be disabled in a table.

When I run the stored procedure (from the app or from the query analyzer) it works fine cause I'm setup as the owner/admin.
However, when users call the stored procedure from the application it gets executed as public which does not have alter persmissions.
I do not want to give alter permissions to public (for obvious reasons).

I was thinking of using SETUSER and SETOWNER but I don't know if it will work (I think because I cannot upgrade permissions using these just change to user of equal or lesser permissions).

Someone had mentioned to me to create a sysadmin user and just SETUSER to that then set it back to public, but again not sure if this will work because public has less permissions than the sysadmin.

I would like to have more info before I try this out and give it back to the client for testing.
Not sure if any of this will work for me, please help.
Thank you for your time.

By the way, I'm using SQL2000My suggestion would be to code an exemption for that stored procedure into your trigger, something like:IF 'myProc' = Object_Name(@.@.procid)
RETURN
-PatP|||Perfect, Exactly what I was looking for.
Thanks a million.

disable trigger syntax?

Code Snippet

CREATE PROCEDURE Staff_NoteGroup_insert

(

@.staffID AS int,

@.owner AS int,

@.subject AS varchar(256),

@.message AS varchar(512),

@.date_add AS DateTime

)

AS

BEGIN TRANSACTION SERIALIZABLE

DECLARE @.id as int

SELECT @.id = (SELECT MAX(id) FROM Staff_NoteGroup) + 1

IF @.id IS NULL

SET @.id = 1

INSERT INTO Staff_NoteGroup VALUES(@.id, @.staffID, @.owner, @.subject, GETDATE(), GETDATE())

IF @.@.error <> 0 BEGIN

ROLLBACK

RETURN

END

DISABLE TRIGGER Staff_Note_insert ON DATABASE

INSERT INTO Staff_Note VALUES(1, @.id, @.owner, @.message, @.date_add)

ENABLE TRIGGER Staff_Note_insert ON DATABASE

IF @.@.error <> 0 BEGIN

ROLLBACK

RETURN

END

COMMIT

GO

Below is the error message.

Msg 156, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 26

Incorrect syntax near the keyword 'TRIGGER'.

Msg 102, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 28

Incorrect syntax near 'ENABLE'.

Msg 102, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 33

Incorrect syntax near 'COMMIT'.

Where is the problem?

I'm using sql server 2005

Thanks,

Max

To execute these commands, you will need to put semicolons before disable and enable:

;DISABLE TRIGGER Staff_Note_insert ON DATABASE

INSERT INTO Staff_Note VALUES(1, @.id, @.owner, @.message, @.date_add)

;ENABLE TRIGGER Staff_Note_insert ON DATABASE

This will allow your code to compile. I don't know that this is a good idea, and it seems like you are not using it right (is Staff_Note_insert a database trigger? or is it a trigger on the Staff_Note table? That would be

;DISABLE TRIGGER Staff_Note_insert ON Staff_note)

But why disable it here? There might be a good reason, so I am not saying it is necessarily a bad thing, but at the very least if deserves a comment as to why you are doing this for other readers who might have to maintain this code later Smile

|||

Aah the "ON DATABASE" part is suppose to be "ON Staff_Note", at first I thought I did not use the ON clause correctly, forgot to change it back.

As for the disabling it, The trigger will update Staff_NoteGroup.date_edit column, everytime a new note is added for the same group, and since this procedure is adding a new group which should have at least a single note, the date_edit should be empty.

I will probably remove the trigger later and replace them using procedure, currently adding the note is still using normal SQL, so I need a trigger to update the NoteGroup.

The database is originally an ms access so there is quite a lot of things to change to make use of the server facilities and also to make it safe for multi-user. I still have a lot to learn.

Regards,

Max

|||Just a quick thought on your code, and please keep in mind that this is just my opinion:

I think it may be a better idea to make some sort of check IN the trigger that decides if you want to perform the function the trigger is doing as compared to disabling and re-enabling the trigger every time. I can't say specifically why, but the idea of disabling a trigger on a regular basis makes me uneasy.

Anyway, just my opinion.

dinsdale.
|||

>>I can't say specifically why, but the idea of disabling a trigger on a regular basis makes me uneasy. <<

No doubt!|||

Ah I have not thought about making a check in the trigger.

Why is it bad to disable and enable trigger every time? does it affect performance? data integrity?

This is the first time I use trigger (other than when I'm still a uni student.), so I'm not very experience with the side-effect.

Anyway, that trigger part is now gone, I remove the trigger completely!!, replaced by stored procedure.

My application is adapting to SQL Server quite well.

Regards,

Max

disable trigger syntax?

Code Snippet

CREATE PROCEDURE Staff_NoteGroup_insert

(

@.staffID AS int,

@.owner AS int,

@.subject AS varchar(256),

@.message AS varchar(512),

@.date_add AS DateTime

)

AS

BEGIN TRANSACTION SERIALIZABLE

DECLARE @.id as int

SELECT @.id = (SELECT MAX(id) FROM Staff_NoteGroup) + 1

IF @.id IS NULL

SET @.id = 1

INSERT INTO Staff_NoteGroup VALUES(@.id, @.staffID, @.owner, @.subject, GETDATE(), GETDATE())

IF @.@.error <> 0 BEGIN

ROLLBACK

RETURN

END

DISABLE TRIGGER Staff_Note_insert ON DATABASE

INSERT INTO Staff_Note VALUES(1, @.id, @.owner, @.message, @.date_add)

ENABLE TRIGGER Staff_Note_insert ON DATABASE

IF @.@.error <> 0 BEGIN

ROLLBACK

RETURN

END

COMMIT

GO

Below is the error message.

Msg 156, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 26

Incorrect syntax near the keyword 'TRIGGER'.

Msg 102, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 28

Incorrect syntax near 'ENABLE'.

Msg 102, Level 15, State 1, Procedure Staff_NoteGroup_insert, Line 33

Incorrect syntax near 'COMMIT'.

Where is the problem?

I'm using sql server 2005

Thanks,

Max

To execute these commands, you will need to put semicolons before disable and enable:

;DISABLE TRIGGER Staff_Note_insert ON DATABASE

INSERT INTO Staff_Note VALUES(1, @.id, @.owner, @.message, @.date_add)

;ENABLE TRIGGER Staff_Note_insert ON DATABASE

This will allow your code to compile. I don't know that this is a good idea, and it seems like you are not using it right (is Staff_Note_insert a database trigger? or is it a trigger on the Staff_Note table? That would be

;DISABLE TRIGGER Staff_Note_insert ON Staff_note)

But why disable it here? There might be a good reason, so I am not saying it is necessarily a bad thing, but at the very least if deserves a comment as to why you are doing this for other readers who might have to maintain this code later Smile

|||

Aah the "ON DATABASE" part is suppose to be "ON Staff_Note", at first I thought I did not use the ON clause correctly, forgot to change it back.

As for the disabling it, The trigger will update Staff_NoteGroup.date_edit column, everytime a new note is added for the same group, and since this procedure is adding a new group which should have at least a single note, the date_edit should be empty.

I will probably remove the trigger later and replace them using procedure, currently adding the note is still using normal SQL, so I need a trigger to update the NoteGroup.

The database is originally an ms access so there is quite a lot of things to change to make use of the server facilities and also to make it safe for multi-user. I still have a lot to learn.

Regards,

Max

|||Just a quick thought on your code, and please keep in mind that this is just my opinion:

I think it may be a better idea to make some sort of check IN the trigger that decides if you want to perform the function the trigger is doing as compared to disabling and re-enabling the trigger every time. I can't say specifically why, but the idea of disabling a trigger on a regular basis makes me uneasy.

Anyway, just my opinion.

dinsdale.
|||

>>I can't say specifically why, but the idea of disabling a trigger on a regular basis makes me uneasy. <<

No doubt!|||

Ah I have not thought about making a check in the trigger.

Why is it bad to disable and enable trigger every time? does it affect performance? data integrity?

This is the first time I use trigger (other than when I'm still a uni student.), so I'm not very experience with the side-effect.

Anyway, that trigger part is now gone, I remove the trigger completely!!, replaced by stored procedure.

My application is adapting to SQL Server quite well.

Regards,

Max

2012年2月19日星期日

Disable trigger

Hi,

can I disable a trigger in Sqlserver 2000? When i run a store procedure who works with one table i want that the trigger doesnt work it. After that the trigger would be enabled again.

I know i can delete it and create it again but something like "ALTER TRIGGER DISABLED" would be ok.

Thanks.I think you want ALTER TABLE myTable DISABLE TRIGGER ALL (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_aa-az_9036.asp) or something very much like it.

-PatP|||fix the procedure?|||fix the procedure?Oh now there's a silly answer!

Fix the problem instead of trying to find a work-around ?!?! Sheeshka, what will they think of next?

-PatP|||What was I thinking...|||Oooh ... oooh - I know the answer to this one :rolleyes: . Create a separate userid and have the trigger check to see if that userid ran the proc that touched the table that fired the trigger. If that user is the active user bypass the trigger, otherwise fire the trigger!
At least, that's what some ** person ** did to a critical set of procs and triggers before I started here, and it would take an act of (insert the appropriate authority here) to do it properly :o .

What some folks won't think of!!|||I actually did exactly that in MS-SQL 6.5 to work around a problem in propriatary code (we didn't have the source to fix the underlying problem).

-PatP

Disable Server Error Messages to Client App (VB)

Hi people!
Can anyone help me with this one? Using SQL Server 2000 and VB5,
calling a stored procedure from VB code. When a message occurs like:
Server: Msg 515, Level 16, State 2, Procedure Ve_KarticeIsplate, Line
235
Cannot insert the value NULL into column 'konto', table
'ibis.dbo.promkred'; column does not allow nulls. INSERT fails.
The statement has been terminated.
VB freaks out, looses the connection to server and stops the execution.
I want to be either be able to disable this message or to ignore it
from client app (using ADO for connection)...
(Simply to ignore the error)Hi VesnaSA,
Here are two excellent articles on error handling in SQL server:
http://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html
A lot of reading but it's worth it.
"VesnaSA" <VesnaVujovicSA@.gmail.com> wrote in message
news:1132235726.691296.264240@.g14g2000cwa.googlegroups.com...
> Hi people!
> Can anyone help me with this one? Using SQL Server 2000 and VB5,
> calling a stored procedure from VB code. When a message occurs like:
> Server: Msg 515, Level 16, State 2, Procedure Ve_KarticeIsplate, Line
> 235
> Cannot insert the value NULL into column 'konto', table
> 'ibis.dbo.promkred'; column does not allow nulls. INSERT fails.
> The statement has been terminated.
> VB freaks out, looses the connection to server and stops the execution.
> I want to be either be able to disable this message or to ignore it
> from client app (using ADO for connection)...
> (Simply to ignore the error)
>|||> Cannot insert the value NULL into column 'konto', table
> 'ibis.dbo.promkred'; column does not allow nulls. INSERT fails.
> The statement has been terminated.
> VB freaks out, looses the connection to server and stops the execution.
> I want to be either be able to disable this message or to ignore it
> from client app (using ADO for connection)...
> (Simply to ignore the error)
>
it would be better though not to pass NULL value to this column? or drop the
constraint from database, though i assume that having nulls in konto column
might be somewhat confusing for people working with account related
application
peter|||Thanx but i handle those transactions with errors in another way, by
placing them in another table,
the point is not to prevent it but to disable the message so that the
procedure can go on for the correct
ones and just skip the ones with errors... To prevent VB to loose the
connection when error happens...
But thanx anyway...|||Thanx Reymond, I'll dig into it, it seams that there is no way to
prevent server from sending the message, thw question is now if the
recordset in ADO can be adjusted so it doesn't report the message?|||I'm not a VB programmer but maybe this will help:
(this is script but you can probably adapt it to VB)
ON ERROR RESUME NEXT
--execute your stored procedure Ve_KarticeIsplate here
If you wish, you can view the errors:
If objConn.errors.count > 0 then
Response.write(objConn.errors.count) & " = " &
objConn.errors(0).description
For counter= 0 to objConn.errors.count
Response.write(objConn.errors(counter).number)
Response.write(objConn.errors(counter).description)
Next
end if
If you're still having problems, post in one of the VB newsgroups.
"VesnaSA" <VesnaVujovicSA@.gmail.com> wrote in message
news:1132238362.365549.85690@.z14g2000cwz.googlegroups.com...
> Thanx Reymond, I'll dig into it, it seams that there is no way to
> prevent server from sending the message, thw question is now if the
> recordset in ADO can be adjusted so it doesn't report the message?
>|||shouldn't you do it in the stored procedure then? using db to handle and
send errors might be expensive, and ADO is not best on handling errors.
also, I assume that account number shouldn't be empty and this is a business
rule, so why don't you check it before you call db? this would save you the
problem. exceptions should not be the way you control flow of your program.
Peter
"VesnaSA" <VesnaVujovicSA@.gmail.com> wrote in message
news:1132237902.217152.65360@.g14g2000cwa.googlegroups.com...
> Thanx but i handle those transactions with errors in another way, by
> placing them in another table,
> the point is not to prevent it but to disable the message so that the
> procedure can go on for the correct
> ones and just skip the ones with errors... To prevent VB to loose the
> connection when error happens...
> But thanx anyway...
>|||"Rogas69" <rogas69@.no_spamers.o2.ie> wrote in message
news:%23GEb9u46FHA.2716@.TK2MSFTNGP11.phx.gbl...
> shouldn't you do it in the stored procedure then? using db to handle and
> send errors might be expensive, and ADO is not best on handling errors.
> also, I assume that account number shouldn't be empty and this is a
> business rule, so why don't you check it before you call db? this would
> save you the problem. exceptions should not be the way you control flow of
> your program.
> Peter
I agree with you on this one.
Error handling has to be done in the database.
The parameters must be validated client side.
But (I'm sure that you saw the BUT coming) error handling also has to be
done in VB.
Imagine these cases:
-the connexion to the database is lost
-someone changed something in the database
-some unforseen error occors in the SP|||First, resolve the bug in the stored procedure which is trying to insert a
NULL into a non-nullable column.
There are techniques for implementing error handling in T-SQL, but this is
only useful for basic things like rolling back transactions and process
flow. The last line of defense is error handling at the application level,
and based on your description of the "VB freaks out", it sounds like perhaps
there no module or function level handling in the application, and the error
is being escalated up the call stack until becomes unrecoverable.
Handling Errors in Visual Basic
Error Handling Hierarchy
http://msdn.microsoft.com/library/d...nghierarchy.asp
Handling Errors and Messages in ADO
http://msdn.microsoft.com/library/d...
9pr.asp
http://msdn.microsoft.com/library/d...rorhandling.asp
"VesnaSA" <VesnaVujovicSA@.gmail.com> wrote in message
news:1132235726.691296.264240@.g14g2000cwa.googlegroups.com...
> Hi people!
> Can anyone help me with this one? Using SQL Server 2000 and VB5,
> calling a stored procedure from VB code. When a message occurs like:
> Server: Msg 515, Level 16, State 2, Procedure Ve_KarticeIsplate, Line
> 235
> Cannot insert the value NULL into column 'konto', table
> 'ibis.dbo.promkred'; column does not allow nulls. INSERT fails.
> The statement has been terminated.
> VB freaks out, looses the connection to server and stops the execution.
> I want to be either be able to disable this message or to ignore it
> from client app (using ADO for connection)...
> (Simply to ignore the error)
>|||True, it is important to implement T-SQL error handling so that the
transaction is rolled back, but any advanced error handling like retry logic
or logging errors is best implemented at the application level.
"Raymond D'Anjou" <rdanjou@.canatradeNOSPAM.com> wrote in message
news:e2XAz%2346FHA.3660@.TK2MSFTNGP09.phx.gbl...
> "Rogas69" <rogas69@.no_spamers.o2.ie> wrote in message
> news:%23GEb9u46FHA.2716@.TK2MSFTNGP11.phx.gbl...
> I agree with you on this one.
> Error handling has to be done in the database.
> The parameters must be validated client side.
> But (I'm sure that you saw the BUT coming) error handling also has to be
> done in VB.
> Imagine these cases:
> -the connexion to the database is lost
> -someone changed something in the database
> -some unforseen error occors in the SP
>

2012年2月14日星期二

disable all triggers

I have a startup stored procedure that dumps data from most tables and
repopulates some startup information. I'd like to disable all the triggers
at the start of this procedure and re-enable them at the end. Is there a
simple way to do this other than one disable line per trigger?
Thanks,
KeithIs there any danger in doing this? Is there a better way?
DECLARE
@.sTriggerName AS VARCHAR(200),
@.sTriggersTable AS VARCHAR(200),
@.sSQL AS VARCHAR(1000)
DECLARE curTriggers INSENSITIVE CURSOR FOR SELECT sysobjects.name AS
TriggerName, sysobjects_1.name AS TriggersTable FROM sysobjects INNER JOIN
sysobjects sysobjects_1 ON sysobjects.parent_obj = sysobjects_1.id WHERE
(OBJECTPROPERTY(sysobjects.id, N'IsTrigger') = 1)
OPEN curTriggers
FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
WHILE @.@.FETCH_STATUS = 0
BEGIN
SET @.sSQL = 'ALTER TABLE [dbo].' + @.sTriggersTable + ' DISABLE TRIGGER ' +
@.sTriggerName
EXEC(@.sSQL)
FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
END
Keith|||you may want to try this
sp_msforeachtable 'Alter table ? disable trigger all'
"Keith G Hicks" wrote:

> Is there any danger in doing this? Is there a better way?
> DECLARE
> @.sTriggerName AS VARCHAR(200),
> @.sTriggersTable AS VARCHAR(200),
> @.sSQL AS VARCHAR(1000)
> DECLARE curTriggers INSENSITIVE CURSOR FOR SELECT sysobjects.name AS
> TriggerName, sysobjects_1.name AS TriggersTable FROM sysobjects INNER JOIN
> sysobjects sysobjects_1 ON sysobjects.parent_obj = sysobjects_1.id WHERE
> (OBJECTPROPERTY(sysobjects.id, N'IsTrigger') = 1)
> OPEN curTriggers
> FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> SET @.sSQL = 'ALTER TABLE [dbo].' + @.sTriggersTable + ' DISABLE TRIGGER ' +
> @.sTriggerName
> EXEC(@.sSQL)
> FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
> END
>
> Keith
>
>|||I can't find sp_msforeachtable in BOL for SQL 2000. I take it it's
undocumented. Anyway, I decided I'd rather only disable triggers that are
currently enabled so as not to enable any that should not be. I'm doing this
first:
CREATE TABLE #EnabledTriggerList (TriggerName VARCHAR(200), TriggerTable
VARCHAR(200))
DECLARE
@.sTriggerName AS VARCHAR(200),
@.sTriggersTable AS VARCHAR(200),
@.sSQL AS VARCHAR(1000)
DECLARE curTriggers INSENSITIVE CURSOR FOR
SELECT name AS TriggerName, OBJECT_NAME(parent_obj) AS TriggerTable
FROM sysobjects
WHERE xtype = 'TR'
AND OBJECTPROPERTY(id,'ExecIsTriggerDisabled
') = 0
OPEN curTriggers
FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
WHILE @.@.FETCH_STATUS = 0
BEGIN
SET @.sSQL = 'ALTER TABLE [dbo].' + @.sTriggersTable + ' DISABLE TRIGGER ' +
@.sTriggerName
EXEC(@.sSQL)
INSERT INTO #EnabledTriggerList (TriggerName, TriggerTable) VALUES
(@.sTriggersTable, @.sTriggerName)
FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
END
CLOSE curTriggers
DEALLOCATE curTriggers
-- Then runnning all my table dump and repop code
-- then this
DECLARE curTriggers INSENSITIVE CURSOR FOR SELECT * FROM #EnabledTriggerList
OPEN curTriggers
FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
WHILE @.@.FETCH_STATUS = 0
BEGIN
SET @.sSQL = 'ALTER TABLE [dbo].' + @.sTriggersTable + ' ENABLE TRIGGER ' +
@.sTriggerName
EXEC(@.sSQL)
FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
END
CLOSE curTriggers
DEALLOCATE curTriggers
It seems to work fine. Should this be safe?
Thanks,
Keith|||That's the way to do it. sp_msforeach* are undoc/supported and they use
cursor internally anyway.
-oj
"Keith G Hicks" <krh@.comcast.net> wrote in message
news:OvoiKjmQGHA.5808@.TK2MSFTNGP12.phx.gbl...
>I can't find sp_msforeachtable in BOL for SQL 2000. I take it it's
> undocumented. Anyway, I decided I'd rather only disable triggers that are
> currently enabled so as not to enable any that should not be. I'm doing
> this
> first:
> CREATE TABLE #EnabledTriggerList (TriggerName VARCHAR(200), TriggerTable
> VARCHAR(200))
> DECLARE
> @.sTriggerName AS VARCHAR(200),
> @.sTriggersTable AS VARCHAR(200),
> @.sSQL AS VARCHAR(1000)
> DECLARE curTriggers INSENSITIVE CURSOR FOR
> SELECT name AS TriggerName, OBJECT_NAME(parent_obj) AS TriggerTable
> FROM sysobjects
> WHERE xtype = 'TR'
> AND OBJECTPROPERTY(id,'ExecIsTriggerDisabled
') = 0
> OPEN curTriggers
> FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> SET @.sSQL = 'ALTER TABLE [dbo].' + @.sTriggersTable + ' DISABLE TRIGGER ' +
> @.sTriggerName
> EXEC(@.sSQL)
> INSERT INTO #EnabledTriggerList (TriggerName, TriggerTable) VALUES
> (@.sTriggersTable, @.sTriggerName)
> FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
> END
> CLOSE curTriggers
> DEALLOCATE curTriggers
> -- Then runnning all my table dump and repop code
> -- then this
> DECLARE curTriggers INSENSITIVE CURSOR FOR SELECT * FROM
> #EnabledTriggerList
> OPEN curTriggers
> FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
> WHILE @.@.FETCH_STATUS = 0
> BEGIN
> SET @.sSQL = 'ALTER TABLE [dbo].' + @.sTriggersTable + ' ENABLE TRIGGER ' +
> @.sTriggerName
> EXEC(@.sSQL)
> FETCH NEXT FROM curTriggers INTO @.sTriggerName, @.sTriggersTable
> END
> CLOSE curTriggers
> DEALLOCATE curTriggers
> It seems to work fine. Should this be safe?
> Thanks,
> Keith
>

disable all SA accounts remotly - access only for low user ?

Hi,
I need to access my web based SQL 2005 express edition database on 1433
using a user with minimal privileges that can only run a stored procedure. I
do this by connecting to IP / port.
Is there anyway I can disable SA using this same method but still allow SA
when I remote desktop to the machine and connect using Management Studio
Express.
I.e if I disable the account the SA account or other admin accounts I cant
login when I RDP into the machine.
The minimal privileges user can simply run a single stored procedure but
must do using 1433.
I just need to disable 1433 access for all other accounts and cant figure
out how to (I guess Management Studio Express connects using 1433 anyway so
im stuck).
If this is the case I guess I need to use SQLXML.
Thanks for any help
Scott
I'm not sure, but you could try playing with something like:
DENY CONNECT ON ENDPOINT::TCP TO "sa"
(Check BOL for exact syntax)
I'm not sure whether such permissions are actually checked for sysadmins (let us know after your
test), and of course, you'd have to make sure some other netlib is used when inside the private
network (like Shared Memory, which only work locally).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Scott" <www.sage-eshop.com> wrote in message news:O$T7b0J3GHA.4764@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I need to access my web based SQL 2005 express edition database on 1433 using a user with minimal
> privileges that can only run a stored procedure. I do this by connecting to IP / port.
> Is there anyway I can disable SA using this same method but still allow SA when I remote desktop
> to the machine and connect using Management Studio Express.
> I.e if I disable the account the SA account or other admin accounts I cant login when I RDP into
> the machine.
> The minimal privileges user can simply run a single stored procedure but must do using 1433.
> I just need to disable 1433 access for all other accounts and cant figure out how to (I guess
> Management Studio Express connects using 1433 anyway so im stuck).
> If this is the case I guess I need to use SQLXML.
> Thanks for any help
> Scott
>

disable all SA accounts remotly - access only for low user ?

Hi,
I need to access my web based SQL 2005 express edition database on 1433
using a user with minimal privileges that can only run a stored procedure. I
do this by connecting to IP / port.
Is there anyway I can disable SA using this same method but still allow SA
when I remote desktop to the machine and connect using Management Studio
Express.
I.e if I disable the account the SA account or other admin accounts I cant
login when I RDP into the machine.
The minimal privileges user can simply run a single stored procedure but
must do using 1433.
I just need to disable 1433 access for all other accounts and cant figure
out how to (I guess Management Studio Express connects using 1433 anyway so
im stuck).
If this is the case I guess I need to use SQLXML.
Thanks for any help
ScottI'm not sure, but you could try playing with something like:
DENY CONNECT ON ENDPOINT::TCP TO "sa"
(Check BOL for exact syntax)
I'm not sure whether such permissions are actually checked for sysadmins (le
t us know after your
test), and of course, you'd have to make sure some other netlib is used when
inside the private
network (like Shared Memory, which only work locally).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Scott" <www.sage-eshop.com> wrote in message news:O$T7b0J3GHA.4764@.TK2MSFTNGP05.phx.gbl...[
vbcol=seagreen]
> Hi,
> I need to access my web based SQL 2005 express edition database on 1433 us
ing a user with minimal
> privileges that can only run a stored procedure. I do this by connecting t
o IP / port.
> Is there anyway I can disable SA using this same method but still allow SA
when I remote desktop
> to the machine and connect using Management Studio Express.
> I.e if I disable the account the SA account or other admin accounts I cant
login when I RDP into
> the machine.
> The minimal privileges user can simply run a single stored procedure but m
ust do using 1433.
> I just need to disable 1433 access for all other accounts and cant figure
out how to (I guess
> Management Studio Express connects using 1433 anyway so im stuck).
> If this is the case I guess I need to use SQLXML.
> Thanks for any help
> Scott
>[/vbcol]