Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2004, 12:55 PM
Authorized User
 
Join Date: Mar 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with nchar fields

Hi all

What I am trying to do is write a simple audit mechanism for a SQL2k database. I can't get funding to buy in a decent audit tool so I am trying to put together something simple myself.

In ASP I have something like

Set oCommand=server.createobject("ADODB.Command")
..
strUpdate="Update myTable set thefield='ABC' where recnum=5'
oCommand.Commandtext=strUpdate
oCommand.Execute numRecs

Thats all fine, now what I want to do is keep a record of all the insert/update/delete commands so I can check back later who did something. So what I've done is create a table called app_audit with
an nchar called theCommand

In the ASP page

strWriteAudit="Insert into app_audit (theCommand) values ("'" &replace(strUpdate,"'","''") &"'")

This does write away the shorter commands to app_audit just fine but the longer commands are truncated at about 2500 characters.

Could anyone give me any clues as to what is happening.

Regards
Graham


 
Old March 20th, 2004, 01:17 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Graham,

Are you sure it's cut of at 2,500 characters? Plain text, or including HTML?
The nchar is capable of holding up to 4,000 characters. Personally, I think that for variable length text, the nvarchar datatype is more suitable than a nchar.
For large text (over 4000) characters, you should use the text datatype, and if you're not really using Unicode in your command text, you can also use the varchar type that holds up to 8,000 characters.

Look up variable-length data types in the SQL Books Online for more details.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 20th, 2004, 01:50 PM
Authorized User
 
Join Date: Mar 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I thought nchar was equivalent to a memo field, so the the main table stores just a pointer and the actual data is held elsewhere.

Regards


 
Old March 20th, 2004, 03:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No, it's not. You need the Text data type for that. According to the BOL, an nchar is a "fixed-length Unicode character data of n characters". Since it has a fixed length, it's best suited for data you expect to be the same size in each record, like SSN or zip codes.

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to resolve #Name? Error problem in few fields jack123 Access 1 August 2nd, 2007 02:08 PM
a problem with adding fields in ssems hassan1365 SQL Server 2005 2 June 6th, 2007 10:57 AM
Formula Fields in Records Problem berniehunt Crystal Reports 1 April 14th, 2006 06:52 PM
Problem to update fields cilla Classic ASP Databases 22 October 26th, 2004 07:36 AM
Problem with Title fields badgolfer HTML Code Clinic 2 July 29th, 2004 06:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.