473,416 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Upsizing MS Access - lessons learnt - Part 2 (Testing) + Insert Into SQL table

Hi there

I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K.

Wish to provide some knowledge gained back to community - hopefully
help others.

1.Question how do you test stored procedure from SQL Server vs MS
Access point of view ?

2.How do you insert many records at same time ?

Questions may seem straight forward to some but I found very
frustrating.

Here goes :-

N.B.
1.Strings e.g. ' or "

See below my sproc.

1.************************************************ *********

A.SQL Server
i.

Query Analyzer - debug procedure - value

'HARLEY.I','03004','A000-AA00',NULL,NULL,getdate(),2003-08-29,0,0,7.5,7.5,7.5,7.5,7.0,'Notes','General',1,2,3 ,getdate(),1,getdate(),null,NULL,0,null,0,null;'HA RLEY.I','03004','A000-AA00',NULL,NULL,getdate(),2003-08-29,0,0,7.5,7.5,7.5,7.5,7.0,'Notes','General',1,2,3 ,getdate(),1,getdate(),null,null,0,null,0,null;

ii.

Query Analyzer

DECLARE @RetCode int
DECLARE @RetMsg varchar(100)
EXEC procTimesheetInsert
@TimesheetDetails
='''HARLEY.I'',''03004'',''A000-AA00'',NULL,NULL,getdate(),2003-08-29,0,0,7.5,7.5,7.5,7.5,7.0,''Notes'',''General'',1 ,2,3,getdate(),1,getdate(),null,NULL,0,null,0,null ;''HARLEY.I'',''03004'',''A000-AA00'',NULL,NULL,getdate(),2003-08-29,0,0,7.5,7.5,7.5,7.5,7.0,''Notes'',''General'',1 ,2,3,getdate(),1,getdate(),null,null,0,null,0,null ;',
@RetCode = @RetCode OUTPUT,
@RetMsg = @RetMsg OUTPUT,
@TimesheetID = NULL

B.Access Side

i.ADO conection

..Source = "SELECT '''' & [re_code] & '''' AS RE_Code1, Test.PR_Code,
'''' & [AC_Code] & '''' AS AC_Code1, Test.CO_Code, Test.CH_Code,
'getdate()' AS TS_LastEdit1, Test.WE_Date, Test.SAT, Test.SUN,
Test.MON, Test.TUE, Test.WED, Test.THU, Test.FRI, '''' & [NOTES] &
'''' AS NOTES1, '''' & [GENERAL] & '''' AS GENERAL1, Test.PO_Number,
Test.WWL_Number, Test.CN_Number, 'getdate()' AS Last_Editby1, '1' AS
User_Confirm1, 'getdate()' AS User_Confirm_Date1, Test.Appd_By,
Test.Appd_Date, '0' AS Approved1, '' AS a, Test.ConcurrencyID, '' AS b
FROM Test;"

2.************************************************ *********
To separate data use ";" - see data

'HARLEY.I','03004','A000-AA00',NULL,NULL,getdate(),2003-08-29,0,0,7.5,7.5,7.5,7.5,7.0,'Notes','General',1,2,3 ,getdate(),1,getdate(),null,NULL,0,null,0,null;'HA RLEY.I','03004','A000-AA00',NULL,NULL,getdate(),2003-08-29,0,0,7.5,7.5,7.5,7.5,7.0,'Notes','General',1,2,3 ,getdate(),1,getdate(),null,null,0,null,0,null;

************************************************** *********
CREATE PROCEDURE [dbo].[procTimesheetInsert](
@TimesheetDetails varchar(5000) = NULL,
@RetCode int = NULL OUTPUT,
@RetMsg varchar(100) = NULL OUTPUT,
@TimesheetID int = NULL)
WITH RECOMPILE
AS
SET NOCOUNT ON

DECLARE @SQLBase varchar(8000), @SQLBase1 varchar(8000)
DECLARE @SQLComplete varchar(8000) ,@SQLComplete1 varchar(8000)
DECLARE @TimesheetCount int, @TimesheetCount1 int
DECLARE @TS_LastEdit smalldatetime
DECLARE @Last_Editby smalldatetime
DECLARE @User_Confirm bit
DECLARE @User_Confirm_Date smalldatetime
DECLARE @DetailCount int
DECLARE @Error int
/* Validate input parameters. Assume success. */

SELECT @RetCode = 1, @RetMsg = ''

IF @TimesheetDetails IS NULL
SELECT @RetCode = 0,
@RetMsg = @RetMsg +
'Timesheet line item(s) required.' + CHAR(13) + CHAR(10)

/* Create a temp table parse out each Timesheet detail from input
parameter string,
count number of detail records and create SQL statement to
insert detail records into the temp table. */
CREATE TABLE #tmpTimesheetDetails
/*
(Counter int IDENTITY (1,1),

SELECT @SQLBase ='INSERT INTO
#tmpTimesheetDetails(RE_Code,PR_Code,AC_Code,WE_Da te,SAT,SUN,MON,TUE,WED,THU,FRI,Notes,General,PO_Nu mber,WWL_Number,CN_Number,User_Confirm,User_Confir m_Date,Approved,ConcurrencyID)
*/

(
RE_Code varchar(50),
PR_Code varchar(50),
AC_Code varchar(50),
CO_Code varchar(50),
CH_Code varchar(50),
TS_LastEdit smalldatetime,
WE_Date smalldatetime,
SAT REAL DEFAULT 0,
SUN REAL DEFAULT 0,
MON REAL DEFAULT 0,
TUE REAL DEFAULT 0,
WED REAL DEFAULT 0,
THU REAL DEFAULT 0,
FRI REAL DEFAULT 0,
Notes varchar(255),
General varchar(50),
PO_Number REAL,
WWL_Number REAL,
CN_Number REAL,
Last_Editby varchar(50),
User_Confirm bit,
User_Confirm_Date smalldatetime,
Appd_By varchar(50),
Appd_Date smalldatetime,
Approved bit,
POSTED_TO_TES smalldatetime,
ConcurrencyID int,
[Timestamp] varchar(50))
SELECT @SQLBase ='INSERT INTO
#tmpTimesheetDetails(RE_Code,PR_Code,AC_Code,CO_Co de,
CH_Code,TS_LastEdit,WE_Date,SAT,SUN,MON,TUE,WED,TH U,FRI,Notes,General,PO_Number,WWL_Number,CN_Number ,Last_Editby,
User_Confirm,User_Confirm_Date,Appd_By
,Appd_Date,Approved,POSTED_TO_TES,ConcurrencyID,[Timestamp])
VALUES ( '
SELECT @TimesheetCount=0
WHILE LEN( @TimesheetDetails) > 1
BEGIN
SELECT @SQLComplete = @SQLBase + LEFT( @TimesheetDetails,
Charindex(';', @TimesheetDetails) -1) + ')'
EXEC(@SQLComplete)
SELECT @TimesheetCount = @TimesheetCount + 1
SELECT @TimesheetDetails = RIGHT( @TimesheetDetails, Len(
@TimesheetDetails)-Charindex(';', @TimesheetDetails))
END

IF (SELECT Count(*) FROM #tmpTimesheetDetails) <> @TimesheetCount
SELECT @RetCode = 0, @RetMsg = @RetMsg + 'Timesheet Details
couldn''t be saved.' + CHAR(13) + CHAR(10)

-- If validation failed, exit proc
IF @RetCode = 0
RETURN

-- If validation ok, continue
SELECT @RetMsg = @RetMsg + 'Timesheet Details ok.' + CHAR(13) +
CHAR(10)
/* RETURN*/

-- Start transaction by inserting into Timesheet table
BEGIN TRAN
INSERT INTO timesheet.dbo.WWL_Timesheets
select RE_Code,PR_Code,AC_Code,CO_Code,
CH_Code,TS_LastEdit,WE_Date,SAT,SUN,MON,TUE,WED,TH U,FRI,Notes,General,PO_Number,WWL_Number,CN_Number ,Last_Editby,
User_Confirm,User_Confirm_Date,Appd_By
,Appd_Date,Approved,POSTED_TO_TES,ConcurrencyID,[Timestamp]
FROM #tmpTimesheetDetails
/*
SELECT RE_Code, PR_Code,AC_Code, WE_Date, SAT, SUN, MON, TUE, WED,
THU, FRI, Notes, General, PO_No, WWL_No, CN_No
*/

/*
SELECT @SQLBase1 ='INSERT INTO WWL_Timesheets (RE_Code,
PR_Code,AC_Code, WE_Date, SAT, SUN, MON, TUE, WED, THU, FRI, Notes,
General, PO_No, WWL_No, CN_No)
VALUES ( '
SELECT @TimesheetCount1=0

WHILE LEN( @TimesheetDetails) > 1
BEGIN
SELECT @SQLComplete1 = @SQLBase1 + LEFT( @TimesheetDetails,
Charindex(';', @TimesheetDetails) -1) + ')'
EXEC(@SQLComplete1)
SELECT @TimesheetCount1 = @TimesheetCount1 + 1
SELECT @TimesheetDetails = RIGHT( @TimesheetDetails, Len(
@TimesheetDetails)-Charindex(';', @TimesheetDetails))
END
RETURN
*/

-- Check if insert succeeded.
IF @@ROWCOUNT = @TimesheetCount AND @@ERROR = 0
BEGIN
commit tran
SELECT @RetCode = 1,
@RetMsg = 'Timesheet added successfully.'
END
ELSE
BEGIN
ROLLBACK TRAN
SELECT @RetCode = 0,
@RetMsg = 'Insertion of new Timesheet failed. Timesheet Details
couldn''t be saved.'
END
RETURN
GO

************************************************** *********
Public Function Test_1()
Dim boolState As Boolean
Dim rstDetails As ADODB.Recordset
Dim strDetails As String
Dim cmd As ADODB.Command
Dim fOK As Boolean
Dim strMsg As String
Dim strOK As String

If gcnn Is Nothing Then
Set gcnn = New ADODB.Connection
End If

If gcnn.State = adStateOpen Then
boolState = True
'do nothing
Else
'If Not IsFormOpen("Frm_Login") Then
'DoCmd.OpenForm "Frm_Login", WindowMode:=acDialog
'End If
GlobalConnection_A = DLookup("[mstrOLEDBConnect]",
"Refresh_FrontEnd_Access", "Not [mstrOLEDBConnect] is null")
If GlobalConnection_A <> "" Or IsNull(GlobalConnection_A) Then
gcnn.ConnectionString = GlobalConnection_A
gcnn.Open
If gcnn.State = adStateOpen Then
boolState = True
Else
boolState = False
End If
'do nothing
End If
End If

'***AIM-Build string from Order Details.
'***AIM-Using ADO Recordset.GetString.

Set rstDetails = New ADODB.Recordset
With rstDetails
.ActiveConnection = CurrentProject.Connection
'***AIM-Sort by Access autonumber field, to preserve entry
Timesheet of details.
'***AIM-Open a default read-only, forward-only recordset
.Source = "SELECT '''' & [re_code] & '''' AS RE_Code1,'''' &
[PR_Code]& '''' AS PR_Code1, '''' & [AC_Code] & '''' AS AC_Code1,
Test.CO_Code, Test.CH_Code, 'getdate()' AS TS_LastEdit1, '''' &
FORMAT([WE_Date],'YYYY/MM/DD') & '''' AS WE_Date1, Test.SAT, Test.SUN,
Test.MON, Test.TUE, Test.WED, Test.THU, Test.FRI, '''' & [NOTES] &
'''' AS NOTES1, '''' & [GENERAL] & '''' AS GENERAL1, Test.PO_Number,
Test.WWL_Number, Test.CN_Number, 'getdate()' AS Last_Editby1, '1' AS
User_Confirm1, 'getdate()' AS User_Confirm_Date1, Test.Appd_By,
Test.Appd_Date, '0' AS Approved1, '' AS a, Test.ConcurrencyID, '' AS b
FROM Test WHERE (((Test.User_Confirm)=False));"
'***AIM-Open a default read-only, forward-only recordset
.Open
'***AIM-Build a string to marshall Timesheet details to the
stored procedure
strDetails = .GetString( _
StringFormat:=adClipString, _
ColumnDelimeter:=",", _
RowDelimeter:=";", _
NullExpr:="NULL")
.Close
MsgBox strDetails
End With
Set rstDetails = Nothing
'Exit Function
'***AIM-Add Timesheet
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = gcnn
.CommandText = "procTimesheetInsert"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@TimesheetDetails",
adVarChar, adParamInput, 5000, strDetails)
.Parameters.Append .CreateParameter("@RetCode", adInteger,
adParamOutput)
.Parameters.Append .CreateParameter("@RetMsg", adVarChar,
adParamOutput, 100)
.Parameters.Append .CreateParameter("@TimesheetID",
adInteger)

.Execute

fOK = .Parameters("@RetCode")
strMsg = .Parameters("@RetMsg")
If fOK Then
Else
strMsg = "Timesheet was not added." & vbCrLf & strMsg
End If
End With
Set cmd = Nothing

End Function
Nov 12 '05 #1
0 4466

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Big Time | last post by:
I have an Access 2000 DB that I've been considering upsizing to SQL Server 2K. I'm wondering if anyone can share their experiences in upsizing and let me know of any tips or pratfalls. I've been...
0
by: ImraneA | last post by:
Hi there I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K. Wish to provide some knowledge gained back to community - hopefully help others. 1.Using Upsizing wizard - will...
1
by: John | last post by:
Hi I am using the upsizing wizard to move a table from access 2000 to sql server. The table does not get exported and all I am getting is a 'Table was skipped, or export failed' error in the...
1
by: Calum Chisholm | last post by:
I'm looking to call the upsizing wizard from within a VBA function, preferably automating the entire upsizing process. Has anyone achieved this under Access 2003? The best I've managed so far is...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
12
by: John | last post by:
Hi We have a front end/back end type access app. We would like to upsize the app to sql server but can not re-write the whole app immediately. Is it feasible to just upsize the backend (data...
3
by: Dave Stone | last post by:
This question appeared years ago in the context of Acc2K and SQL Server 7, but no replies were posted. HOWEVER!! It still seems to be a problem with Acc XP and SQL Server 2000. Surely someone has a...
3
by: Devonish | last post by:
I am planning to convert an existing Access database which has a back end (data tables and relationships only) on a server and a copy of the front end (form, queries, reports) on each of about a...
7
by: JM | last post by:
I'm using Access 2003 to attempt an upsize to SQL Server 2000. The Upsizing Wizard is giving me tons of problems with error messages like: 1. "Object is invalid. Extended properties not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.