all groups > sql server programming > march 2004 >
You're in the

sql server programming

group:

Best practice for storing email like text


Re: Best practice for storing email like text Anith Sen
3/28/2004 9:22:27 PM
sql server programming:
Not sure why you are concerned with 256, since NVARCHAR datatype can handle
upto 4000 characters. Which version of SQL Server are you using?

--
Anith

Best practice for storing email like text Charlie Dison
3/28/2004 10:00:35 PM
Hi there,
Among the features of my asp.net application is a need for two users to
communicate with each other. Questioner will ask a question, responder may
simply answer or respond with a question. There may be several threads.
There is no way to know what the maximum text length might be. I was
thinking of something like this.

Create table commDet (c_commid long not null, c_commseq smallint not null,
c_commtext nvarchar (256))

There would be a CommHdr file to store other information about the
conversation.

In my asp.net application I would build a string with the text and if
it's longer than 256 I'd write as many records as it takes incrementing the
c_commseq variable. Isn't it try that nvarchar only takes up as much space
as needed? If so, why don't I just define a really large size for the text
field and not worry about writing multiple records. Is there a better way
to store paragraphs of text?

RE: Best practice for storing email like text v-binyao NO[at]SPAM online.microsoft.com (
3/29/2004 9:08:16 AM
Hi Charlie,

From your description, I understood that you'd like to implement your ASP.NET application for two users'
communication with simple questions and answers. You have created the table with one NVARCHAR(256)
field but concerned about the maximum text length 256. Have I understood the issue correctly and
completely? If there is anything I misunderstood, please feel free to let me know.


As Anith has pointed it out, SQL Server supports 4000 characters for the NVARCHAR field. We can exceed
this 256 length up to maximum 4000 running the following Alter Table...Alter Column statement:

------------------------------------------------------------------------------------------------
Alter Table commDet Alter Column c_commtext nvarchar (4000)
------------------------------------------------------------------------------------------------

On the other hand, for better ways to store and retrieve binary large object - BLOB (Text, Image etc.), you
can try to use the StreamReader object and a string in ASP.NET to write BLOB data to a Text column in SQL
Server.

The following code also describes how to load BLOB data from a Text column in SQL Server database into
a Char array, and display it in the browser.

If you prefer a documented article, I believe the following Knowledge Base (KB) article is the best practices
to handle the BLOB data in ASP.NET:

326502 HOW TO: Read and Write BLOB Data by Using ADO.NET Through ASP.NET
http://support.microsoft.com/?id=326502

Code Sample below:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Suppose the pub_info table contains a Text column called "pr_info" in Pubs database.

Sub Button3_Click demonstrates how to store data into a text column.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim con As New SqlConnection("SERVER=.;UID=uid;PWD=pwd;DATABASE=Pubs")
Dim cmd As New SqlCommand("UPDATE pub_info SET pr_info=@txt WHERE
pub_id=0736 ", con)
Dim sr As StreamReader = New StreamReader(Server.MapPath("Test.txt"))
Dim s As String = sr.ReadToEnd
sr.Close()
Dim P As New SqlParameter("@txt", s)
cmd.Parameters.Add(P)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
cmd = Nothing
con = Nothing
Response.Write("Text saved to database")
End Sub

Sub Button4_Click retrieves data from a text column.

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim con As New
SqlConnection("Server=yileiw2;uid=sqlauth;pwd=sqlauth;database=pubs")
Dim da As New SqlDataAdapter("Select * From pub_info", con)
Dim ds As New DataSet()

da.Fill(ds, "Pub_info")
Dim myRow As DataRow
myRow = ds.Tables("Pub_info").Rows(0)

Dim MyData() As Char
MyData = myRow("pr_info")

Response.Buffer = True
Response.ContentType = "text/plain"
Response.Write(MyData)
End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Does that answer your question Charlie? Please apply my suggestions above and let me know if this helps
resolve your problem. If there is anything more I can do to assist you, please feel free to post it in the group.

Best regards,

Billy Yao
Microsoft Online Support
----------------------------------------------------
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only. Thanks.


RE: Best practice for storing email like text anonymous NO[at]SPAM discussions.microsoft.com
3/31/2004 7:31:54 AM
Thank You, your advise was helpful.

[quoted text, click to view]
following Knowledge Base (KB) article is the best
practices
[quoted text, click to view]
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''
[quoted text, click to view]
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''
[quoted text, click to view]
AddThis Social Bookmark Button