| Author |
Topic |
|
cduance
Starting Member
6 Posts |
Posted - 2010-09-07 : 16:47:09
|
I have a stored Procedure which is as followsINSERT INTO Reporting.tblServerMonitor(ServerMonitorID, FK_tblServers_ServerID, ServerStatus, ServerTimeStamp) SELECT ServerMonitorID, FK_tblServers_ServerID, ServerStatus, ServerTimeStamp FROM ServerService.tblServerMonitor WHERE ArchiveBit = 0-- ====================================================-- Reset ArchiveBit to 1 for Archived Records-- ==================================================== UPDATE ServerService.tblServerMonitor SET ArchiveBit = 1 WHERE ArchiveBit = 0-- ====================================================-- Update Server Monitor Record for ServerDriveID-- ==================================================== UPDATE ServerService.tblServerMonitor SET ServerStatus = 1, ServerTimeStamp = GETDATE(), ArchiveBit = 0 WHERE ServerMonitorID = 1 However, the only bit that seems to run is the update. An additional record is not copied to the Reporting table before the record is updated. If I run this stand alone then it works but being called from a web page only updates the record which is the final bit?Any ideas.Many thanksCharles |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
cduance
Starting Member
6 Posts |
Posted - 2010-09-07 : 16:57:13
|
CheersProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim strCmd As String = "ServerService.ServerMonitorUpdate" Dim myConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ServerConnString").ConnectionString Dim myConn As New SqlConnection(myConnStr) Dim myColl As New NameValueCollection myColl = Request.QueryString Using mySQLCmd As New SqlCommand(strCmd, myConn) myConn.Open() mySQLCmd.CommandType = CommandType.StoredProcedure mySQLCmd.CommandText = strCmd mySQLCmd.Parameters.Add("@ServerMonitorID", SqlDbType.Int).Value = myColl("ServerID") mySQLCmd.ExecuteNonQuery() End Using End Sub |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
cduance
Starting Member
6 Posts |
Posted - 2010-09-07 : 17:17:20
|
The stored proc is the same as in my first post. I just deleted out the additional bits but here it is. Its MS SQL 2008/****** Object: StoredProcedure [ServerService].[ServerMonitorUpdate] Script Date: 09/07/2010 21:25:27 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- ======================================================-- Author: Me-- Create date: 19/06/2010-- Description: Updates the Server record in the ServerMonitor table-- Change: Added Archive Procedure on 24/08/2010-- ======================================================ALTER PROCEDURE [ServerService].[ServerMonitorUpdate] -- Add the parameters for the stored procedure here @ServerMonitorID IntASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. --SET NOCOUNT ON;-- ====================================================-- Archive Records with ArchiveBit = 0-- ==================================================== INSERT INTO Reporting.tblServerMonitor(ServerMonitorID, FK_tblServers_ServerID, ServerStatus, ServerTimeStamp) (SELECT ServerMonitorID, FK_tblServers_ServerID, ServerStatus, ServerTimeStamp FROM ServerService.tblServerMonitor WHERE ArchiveBit = 0)-- ====================================================-- Reset ArchiveBit to 1 for Archived Records-- ==================================================== UPDATE ServerService.tblServerMonitor SET ArchiveBit = 1 WHERE ArchiveBit = 0-- ====================================================-- Update Server Monitor Record for ServerDriveID-- ==================================================== UPDATE ServerService.tblServerMonitor SET ServerStatus = 1, ServerTimeStamp = GETDATE(), ArchiveBit = 0 WHERE ServerMonitorID = @ServerMonitorIDENDGO |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
cduance
Starting Member
6 Posts |
Posted - 2010-09-07 : 17:28:41
|
| The record is being updated so it is passing the correct serverID the problem seems to be that it does not do either of the two queries just the last one which seems very weird. I don't know if I need to get the SProc to do each query seperately? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
cduance
Starting Member
6 Posts |
Posted - 2010-09-07 : 17:49:43
|
| OK thanks for your help. Ill let you know when I find the issue |
 |
|
|
cduance
Starting Member
6 Posts |
Posted - 2010-09-08 : 14:51:38
|
| Permissions :(Due to taking data from one table in schema A and trying to insert into schema B |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-09-09 : 02:34:10
|
quote: Originally posted by cduance Permissions :(Due to taking data from one table in schema A and trying to insert into schema B
Did SQL not raise an error? (Or perhaps the APP didn't catch it ) |
 |
|
|
|