How to store HTML code in SQL server table

P

Peter Afonin

Hello,

I'm creating something like a web site builder in ASP.Net, and I need to
store an HTML code in the SQL server table. If my customer just enters an
HTML code, it is stored in the SQL server table like this: <table
cellSpacing="0" cellPadding="0" width="760"
border=&quot;0&quot;&gt;, instead of <table cellSpacing="0" cellPadding="0"
width="760" border="0">

This significantly increases the size of the stored code.

Are there any conversion functions or something like this to avoid it? Where
this conversion should be done - in ASP.Net or SQL server? How do I convert
it back to create an HTML page?

Please note that I must use the Unicode data type - ntext, nchar etc, since
I'm using some Cyrillic characters.

I would appreciate your advice very much.

Thank you,
 
J

Jeffrey Palermo [MCP]

Peter,
ntext in SQL Server will store Html markup just fine. You are encoding
your html before storing it in the database. Find out where you are
encoding the markup and change that code. Debug your code and make sure
that you are indeed sending pure html to the database. SQL Server will not
automatically encode html, so your code is doing it somewhere.

Best regards,
Jeffrey Palermo
 
W

Wayne Snyder

As the other poster states, it is not SQL that is doing the encoding, it is
something else...

Also, if the html pages will be less than 4000 unicode characters, you may
prefer to strore the data in a varchar column.

--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)

I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
 
P

Peter Afonin

Thank you everyone for your suggestions.

So far when I use ntext it works OK, then I use the Literal control and
Server.Decode to write the data in ASP.Net.

Peter

Wayne Snyder said:
As the other poster states, it is not SQL that is doing the encoding, it is
something else...

Also, if the html pages will be less than 4000 unicode characters, you may
prefer to strore the data in a varchar column.

--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)

I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
 
J

Jeffrey Palermo [MCP]

Wayne,
Maybe it's just a typo, but varchar cannot be properly used with unicode
and has a maximum length of 8000 characters. nvarchar has a limit of 4000
characters and should be used for all applications for maintenance purposes
(since most applications will have to support unicode in the future).


--
Best regards,
Jeffrey Palermo
Blog: http://dotnetjunkies.com/weblog/jpalermo

Wayne Snyder said:
As the other poster states, it is not SQL that is doing the encoding, it is
something else...

Also, if the html pages will be less than 4000 unicode characters, you may
prefer to strore the data in a varchar column.

--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)

I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top