 |
| 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
|
|
|
|

March 20th, 2004, 12:55 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 20th, 2004, 01:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

March 20th, 2004, 01:50 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 20th, 2004, 03:10 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|
 |