ChrisQuick
Programmer
I have a procedure in SQL Server 2000 written to support on Online Complaint Tracking program.
The procedure runs OK in SQL Query Analyzer, but when used with ADO in ASP, produces the error:
[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated.
-2147217833
I don't have any binary data in the referenced tables, and I don't believe any of the values being passed from the form exceed the column lengths so, I am kind of stumped here..
Any ideas or suggestions??
Here is the ASP code:
<%
Option Explicit
Response.Buffer = True
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.CacheControl = "no-cache"
' For documentation on the include files, see each individual file.
%>
<!-- #include virtual="common/writepretty.inc"-->
<!-- #include virtual="common/adovbs.inc"-->
<%
Dim strLastName
Dim strFirstName
Dim strHouseNo
Dim strStreetName
Dim strAptNo
Dim strAreaCode
Dim strPhonePrefix
Dim strPhoneSuffix
Dim strPhoneExt
Dim strEmailAccount
Dim strEmailDomainName
Dim selDomain
Dim strCheckAdd
Dim strCompHouseNo
Dim strCompStreetName
Dim strCompAptNo
Dim selCompType
Dim strDesc
Dim objADOConn, strConnectionString, objADORecs, objField
Dim booError
booError = "FALSE"
' READ THE INFORMATION PASSED FROM THE FORM
'*************************************************
strLastName = UCase(Request.Form("txtLastName")
strFirstName = UCase(Request.Form("txtFirstName")
strHouseNo = UCase(Request.Form("txtHouseNo")
strStreetName = UCase(Request.Form("txtStreetName")
strAptNo = UCase(Request.Form("txtAptNo")
strAreaCode = UCase(Request.Form("txtAreaCode")
strPhonePrefix = UCase(Request.Form("txtPhonePrefix")
strPhoneSuffix = UCase(Request.Form("txtPhoneSuffix")
strPhoneExt = UCase(Request.Form("txtPhoneExt")
strEmailAccount = UCase(Request.Form("txtEmailAccount")
strEmailDomainName = UCase(Request.Form("txtEmailDomainName")
selDomain = UCase(Request.Form("selDomain")
strCompHouseNo = UCase(Request.Form("txtCompHouseNo")
strCompStreetName = UCase(Request.Form("txtCompStreetName")
strCompAptNo = UCase(Request.Form("txtCompAptNo")
selCompType = UCase(Request.Form("selCompType")
strDesc = UCase(Replace(Request.Form("txtDesc", vbCrLf, "
")
' CHECK THE INFORMATION PASSED FROM THE FORM
'*************************************************
If strLastName & " " = " " Then
WritePretty "We need your last name.
Please hit the back button on your browser and try again."
Response.End
End If
If strFirstName & " " = " " Then
WritePretty "We need your first name.
Please hit the back button on your browser and try again."
Response.End
End If
If strHouseNo & " " = " " Then
WritePretty "We need your house number.
Please hit the back button on your browser and try again."
Response.End
End If
If strStreetName & " " = " " Then
WritePretty "We need your street name.
Please hit the back button on your browser and try again."
Response.End
End If
If strAreaCode & " " = " " Then
WritePretty "We need your area code.
Please hit the back button on your browser and try again."
Response.End
End If
If strPhonePrefix & " " = " " Then
WritePretty "We need your phone number.
Please hit the back button on your browser and try again."
Response.End
End If
If strPhoneSuffix & " " = " " Then
WritePretty "We need your phone number.
Please hit the back button on your browser and try again."
Response.End
End If
If strEmailAccount & " " = " " Then
WritePretty "We need your email address.
Please hit the back button on your browser and try again."
Response.End
End If
If strEmailDomainName & " " = " " Then
WritePretty "We need your email address.
Please hit the back button on your browser and try again."
Response.End
End If
If selDomain & " " = " " Then
WritePretty "We need your email address.
Please hit the back button on your browser and try again."
Response.End
End If
If selCompType & " " = " " Then
WritePretty "We need to know what type of complaint this is.
Please hit the back button on your browser and try again."
Response.End
End If
If strDesc & " " = " " Then
WritePretty "We need a description of the problem.
Please hit the back button on your browser and try again."
Response.End
End If
strConnectionString = "PROVIDER=MSDASQL; DRIVER={SQL Server}; SERVER=myserver; DATABASE=Complaint; UID=theUser;PWD=thePass;"
Set objADOConn = Server.CreateObject("adodb.Connection"
Set objADORecs = Server.CreateObject("ADODB.Recordset"
objADOConn.Open strConnectionString
On Error Resume Next
objADOConn.AddNewComplaint strLastName, strFirstName, strHouseNo, strStreetName, strAptNo, strAreaCode, strPhonePrefix, strPhoneSuffix, strPhoneExt, strEmailAccount, strEmailDomainName, selDomain, strCompHouseNo, strCompStreetName, strCompAptNo, selCompType, strDesc, objADORecs
If Err.Number <> 0 Then
booError = "True"
End If
If booError = "True" Then
WritePretty "There has been an error:
" & Err.Description & "
" & Err.Number
Response.End
Else
For Each objField in objADORecs.Fields
Response.Write objField.Name & "
"
Next
Do While Not objADORecs.EOF
For Each objField in objADORecs.Fields
Response.Write objADORecs.Value & "
"
Next
'Advance the recordset
objADORecs.MoveNext
Loop
End If
This is the Stored Procedure:
CREATE PROCEDURE dbo.AddNewComplaint(
/* Contact Info */
@strLastName [varchar](50),
@strFirstName [varchar](50),
@intHouseNo [int],
@strStreetName [varchar](50),
@strAptNo [varchar](10) = null,
@intAreaCode [varchar](3),
@intPhonePrefix [varchar](3),
@intPhoneSuffix [varchar](4),
@intPhoneExt [varchar](4) = null,
@strEmailAccount [varchar](20),
@strEmailDomainName [varchar](20),
@strEmailDomainType [varchar](3),
/* Complaint Location Info */
@strCompHouseNo [varchar](6) = null,
@strCompStreetName[varchar](86) = null,
@strCompAptNo [varchar](6) = null,
/* Complaint Info */
@intCompType [int],
@strDesc [varchar](500),
/* Calculated variables */
@myDate [datetime] = null,
@mydow [varchar](10) = null,
@deadline [datetime] = null,
@ContactID [int] = null,
@ComplaintAssigned_Id [int] = null,
@ComplaintStatusType [INT] = null,
@ComplaintId [INT] = null,
@ComplaintConcatAddress [varchar](100) = null
)
AS
IF NOT EXISTS(SELECT 'True' FROM [Complaint].[dbo].[Contacts] WHERE [ContactEmailAddressName]= @strEmailAccount AND [ContactEmailAddressServer] = @strEmailDomainName)
BEGIN
--This means the record isn't in there already, let's go ahead and add it
INSERT INTO [Complaint].[dbo].[Contacts] (
[ContactFirstName],
[ContactlastName],
[ContactAddressHouseNum],
[ContactAddressRoadName],
[ContactAddressAptNumber],
[ContactAreaCode],
[ContactPhonePrefix],
[ContactPhoneNumber],
[ContactPhoneExt],
[ContactEmailAddressName],
[ContactEmailAddressServer],
[ContactEmailAddressDomain]
)
VALUES (
@strFirstName,
@strLastName,
@intHouseNo,
@strStreetName,
@strAptNo,
@intAreaCode,
@intPhonePrefix,
@intPhoneSuffix,
@intPhoneExt,
@strEmailAccount,
@strEmailDomainName,
@strEmailDomainType
)
END
SELECT @ContactID = (select ContactContact_Id from [Complaint].[dbo].[Contacts] WHERE [ContactEmailAddressName]= @strEmailAccount AND [ContactEmailAddressServer] = @strEmailDomainName)
SELECT @myDate = getdate()
SELECT @mydow = DATENAME(dw,@myDate)
SELECT @deadline = (
SELECT DATEADD(DAY,(SELECT
Case @mydow
WHEN 'Sunday' THEN 3
WHEN 'Monday' THEN 3
WHEN 'Tuesday' THEN 3
WHEN 'Wednesday' THEN 5
WHEN 'Thursday' THEN 5
WHEN 'Friday' THEN 5
WHEN 'Saturday' THEN 5
End
),@myDate))
IF EXISTS(SELECT 'True' FROM [Complaint].[dbo].[ComplaintTypes] WHERE ComplaintType_Id = @intCompType)
BEGIN
-- we know what type of complaint it is, so we know who to give it to. set the staus = autoassigned.
SELECT @ComplaintAssigned_Id = (SELECT ComplaintAssigned_Id FROM ComplaintTypes WHERE ComplaintType_Id = @intCompType)
SELECT @ComplaintStatusType = '2'
END
ELSE
BEGIN
-- we do not know who to give it to, so give it the admin user and set status = new
SELECT @ComplaintAssigned_Id = '1'
SELECT @ComplaintStatusType = '1'
END
INSERT INTO [Complaint].[dbo].[Complaints] (
[Contact_Id],
[ComplaintSubmittialMethod_Id],
[ComplaintType_Id],
[ComplaintStatusType_Id],
[ComplaintAssignedCityEmployee_Id],
[ComplaintDesc],
[ComplaintActionDueDate]
)
VALUES (
@ContactID,
'2',
@intCompType,
@ComplaintStatusType,
@ComplaintAssigned_Id ,
@strDesc,
@deadline
)
SELECT @ComplaintId = (SELECT SCOPE_IDENTITY())
SELECT @ComplaintConcatAddress = (SELECT cast(@strCompHouseNo AS varchar(5)) + ' ' + @strCompStreetName + ' ' + @strCompAptNo)
IF (LEN(@ComplaintConcatAddress) > 3)
BEGIN
INSERT INTO [Complaint].[dbo].[ComplaintLocations] (
[ComplaintLocationComplaint_Id],
[ComplaintLocationAddress]
)
VALUES (
@ComplaintId,
@ComplaintConcatAddress
)
END
ELSE
BEGIN
INSERT INTO [Complaint].[dbo].[ComplaintLocations] (
[ComplaintLocationComplaint_Id]
)
VALUES (
@ComplaintId
)
END
SELECT dbo.Complaints.Complaint_Id, dbo.CityEmployees.CityEmployeeEmailAdd
FROM dbo.Complaints INNER JOIN
dbo.CityEmployees ON dbo.Complaints.ComplaintAssignedCityEmployee_Id = dbo.CityEmployees.CityEmployee_Id
WHERE dbo.Complaints.Complaint_Id = @ComplaintId
GO
cquick@geotg.com
Geographic Information System (GIS), ASP, some Oracle
The procedure runs OK in SQL Query Analyzer, but when used with ADO in ASP, produces the error:
[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated.
-2147217833
I don't have any binary data in the referenced tables, and I don't believe any of the values being passed from the form exceed the column lengths so, I am kind of stumped here..
Any ideas or suggestions??
Here is the ASP code:
<%
Option Explicit
Response.Buffer = True
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.CacheControl = "no-cache"
' For documentation on the include files, see each individual file.
%>
<!-- #include virtual="common/writepretty.inc"-->
<!-- #include virtual="common/adovbs.inc"-->
<%
Dim strLastName
Dim strFirstName
Dim strHouseNo
Dim strStreetName
Dim strAptNo
Dim strAreaCode
Dim strPhonePrefix
Dim strPhoneSuffix
Dim strPhoneExt
Dim strEmailAccount
Dim strEmailDomainName
Dim selDomain
Dim strCheckAdd
Dim strCompHouseNo
Dim strCompStreetName
Dim strCompAptNo
Dim selCompType
Dim strDesc
Dim objADOConn, strConnectionString, objADORecs, objField
Dim booError
booError = "FALSE"
' READ THE INFORMATION PASSED FROM THE FORM
'*************************************************
strLastName = UCase(Request.Form("txtLastName")
strFirstName = UCase(Request.Form("txtFirstName")
strHouseNo = UCase(Request.Form("txtHouseNo")
strStreetName = UCase(Request.Form("txtStreetName")
strAptNo = UCase(Request.Form("txtAptNo")
strAreaCode = UCase(Request.Form("txtAreaCode")
strPhonePrefix = UCase(Request.Form("txtPhonePrefix")
strPhoneSuffix = UCase(Request.Form("txtPhoneSuffix")
strPhoneExt = UCase(Request.Form("txtPhoneExt")
strEmailAccount = UCase(Request.Form("txtEmailAccount")
strEmailDomainName = UCase(Request.Form("txtEmailDomainName")
selDomain = UCase(Request.Form("selDomain")
strCompHouseNo = UCase(Request.Form("txtCompHouseNo")
strCompStreetName = UCase(Request.Form("txtCompStreetName")
strCompAptNo = UCase(Request.Form("txtCompAptNo")
selCompType = UCase(Request.Form("selCompType")
strDesc = UCase(Replace(Request.Form("txtDesc", vbCrLf, "
")
' CHECK THE INFORMATION PASSED FROM THE FORM
'*************************************************
If strLastName & " " = " " Then
WritePretty "We need your last name.
Please hit the back button on your browser and try again."
Response.End
End If
If strFirstName & " " = " " Then
WritePretty "We need your first name.
Please hit the back button on your browser and try again."
Response.End
End If
If strHouseNo & " " = " " Then
WritePretty "We need your house number.
Please hit the back button on your browser and try again."
Response.End
End If
If strStreetName & " " = " " Then
WritePretty "We need your street name.
Please hit the back button on your browser and try again."
Response.End
End If
If strAreaCode & " " = " " Then
WritePretty "We need your area code.
Please hit the back button on your browser and try again."
Response.End
End If
If strPhonePrefix & " " = " " Then
WritePretty "We need your phone number.
Please hit the back button on your browser and try again."
Response.End
End If
If strPhoneSuffix & " " = " " Then
WritePretty "We need your phone number.
Please hit the back button on your browser and try again."
Response.End
End If
If strEmailAccount & " " = " " Then
WritePretty "We need your email address.
Please hit the back button on your browser and try again."
Response.End
End If
If strEmailDomainName & " " = " " Then
WritePretty "We need your email address.
Please hit the back button on your browser and try again."
Response.End
End If
If selDomain & " " = " " Then
WritePretty "We need your email address.
Please hit the back button on your browser and try again."
Response.End
End If
If selCompType & " " = " " Then
WritePretty "We need to know what type of complaint this is.
Please hit the back button on your browser and try again."
Response.End
End If
If strDesc & " " = " " Then
WritePretty "We need a description of the problem.
Please hit the back button on your browser and try again."
Response.End
End If
strConnectionString = "PROVIDER=MSDASQL; DRIVER={SQL Server}; SERVER=myserver; DATABASE=Complaint; UID=theUser;PWD=thePass;"
Set objADOConn = Server.CreateObject("adodb.Connection"
Set objADORecs = Server.CreateObject("ADODB.Recordset"
objADOConn.Open strConnectionString
On Error Resume Next
objADOConn.AddNewComplaint strLastName, strFirstName, strHouseNo, strStreetName, strAptNo, strAreaCode, strPhonePrefix, strPhoneSuffix, strPhoneExt, strEmailAccount, strEmailDomainName, selDomain, strCompHouseNo, strCompStreetName, strCompAptNo, selCompType, strDesc, objADORecs
If Err.Number <> 0 Then
booError = "True"
End If
If booError = "True" Then
WritePretty "There has been an error:
" & Err.Description & "
" & Err.Number
Response.End
Else
For Each objField in objADORecs.Fields
Response.Write objField.Name & "
"
Next
Do While Not objADORecs.EOF
For Each objField in objADORecs.Fields
Response.Write objADORecs.Value & "
"
Next
'Advance the recordset
objADORecs.MoveNext
Loop
End If
This is the Stored Procedure:
CREATE PROCEDURE dbo.AddNewComplaint(
/* Contact Info */
@strLastName [varchar](50),
@strFirstName [varchar](50),
@intHouseNo [int],
@strStreetName [varchar](50),
@strAptNo [varchar](10) = null,
@intAreaCode [varchar](3),
@intPhonePrefix [varchar](3),
@intPhoneSuffix [varchar](4),
@intPhoneExt [varchar](4) = null,
@strEmailAccount [varchar](20),
@strEmailDomainName [varchar](20),
@strEmailDomainType [varchar](3),
/* Complaint Location Info */
@strCompHouseNo [varchar](6) = null,
@strCompStreetName[varchar](86) = null,
@strCompAptNo [varchar](6) = null,
/* Complaint Info */
@intCompType [int],
@strDesc [varchar](500),
/* Calculated variables */
@myDate [datetime] = null,
@mydow [varchar](10) = null,
@deadline [datetime] = null,
@ContactID [int] = null,
@ComplaintAssigned_Id [int] = null,
@ComplaintStatusType [INT] = null,
@ComplaintId [INT] = null,
@ComplaintConcatAddress [varchar](100) = null
)
AS
IF NOT EXISTS(SELECT 'True' FROM [Complaint].[dbo].[Contacts] WHERE [ContactEmailAddressName]= @strEmailAccount AND [ContactEmailAddressServer] = @strEmailDomainName)
BEGIN
--This means the record isn't in there already, let's go ahead and add it
INSERT INTO [Complaint].[dbo].[Contacts] (
[ContactFirstName],
[ContactlastName],
[ContactAddressHouseNum],
[ContactAddressRoadName],
[ContactAddressAptNumber],
[ContactAreaCode],
[ContactPhonePrefix],
[ContactPhoneNumber],
[ContactPhoneExt],
[ContactEmailAddressName],
[ContactEmailAddressServer],
[ContactEmailAddressDomain]
)
VALUES (
@strFirstName,
@strLastName,
@intHouseNo,
@strStreetName,
@strAptNo,
@intAreaCode,
@intPhonePrefix,
@intPhoneSuffix,
@intPhoneExt,
@strEmailAccount,
@strEmailDomainName,
@strEmailDomainType
)
END
SELECT @ContactID = (select ContactContact_Id from [Complaint].[dbo].[Contacts] WHERE [ContactEmailAddressName]= @strEmailAccount AND [ContactEmailAddressServer] = @strEmailDomainName)
SELECT @myDate = getdate()
SELECT @mydow = DATENAME(dw,@myDate)
SELECT @deadline = (
SELECT DATEADD(DAY,(SELECT
Case @mydow
WHEN 'Sunday' THEN 3
WHEN 'Monday' THEN 3
WHEN 'Tuesday' THEN 3
WHEN 'Wednesday' THEN 5
WHEN 'Thursday' THEN 5
WHEN 'Friday' THEN 5
WHEN 'Saturday' THEN 5
End
),@myDate))
IF EXISTS(SELECT 'True' FROM [Complaint].[dbo].[ComplaintTypes] WHERE ComplaintType_Id = @intCompType)
BEGIN
-- we know what type of complaint it is, so we know who to give it to. set the staus = autoassigned.
SELECT @ComplaintAssigned_Id = (SELECT ComplaintAssigned_Id FROM ComplaintTypes WHERE ComplaintType_Id = @intCompType)
SELECT @ComplaintStatusType = '2'
END
ELSE
BEGIN
-- we do not know who to give it to, so give it the admin user and set status = new
SELECT @ComplaintAssigned_Id = '1'
SELECT @ComplaintStatusType = '1'
END
INSERT INTO [Complaint].[dbo].[Complaints] (
[Contact_Id],
[ComplaintSubmittialMethod_Id],
[ComplaintType_Id],
[ComplaintStatusType_Id],
[ComplaintAssignedCityEmployee_Id],
[ComplaintDesc],
[ComplaintActionDueDate]
)
VALUES (
@ContactID,
'2',
@intCompType,
@ComplaintStatusType,
@ComplaintAssigned_Id ,
@strDesc,
@deadline
)
SELECT @ComplaintId = (SELECT SCOPE_IDENTITY())
SELECT @ComplaintConcatAddress = (SELECT cast(@strCompHouseNo AS varchar(5)) + ' ' + @strCompStreetName + ' ' + @strCompAptNo)
IF (LEN(@ComplaintConcatAddress) > 3)
BEGIN
INSERT INTO [Complaint].[dbo].[ComplaintLocations] (
[ComplaintLocationComplaint_Id],
[ComplaintLocationAddress]
)
VALUES (
@ComplaintId,
@ComplaintConcatAddress
)
END
ELSE
BEGIN
INSERT INTO [Complaint].[dbo].[ComplaintLocations] (
[ComplaintLocationComplaint_Id]
)
VALUES (
@ComplaintId
)
END
SELECT dbo.Complaints.Complaint_Id, dbo.CityEmployees.CityEmployeeEmailAdd
FROM dbo.Complaints INNER JOIN
dbo.CityEmployees ON dbo.Complaints.ComplaintAssignedCityEmployee_Id = dbo.CityEmployees.CityEmployee_Id
WHERE dbo.Complaints.Complaint_Id = @ComplaintId
GO
cquick@geotg.com
Geographic Information System (GIS), ASP, some Oracle