J
Jim Bayers
I'm opening a connection to our sql server and puting it in a
memorystream so that, later on, a user can save the data as an xml file.
Our question is, how hard is this on our server? What if we have a meg
of data? Will that take up a meg of ram?
Can this bring the server to its knees? How easily?
Function getMemStream() As MemoryStream
'MemoryStream ReturnStream = new MemoryStream();
'Create the return memorystream object that will hold
'the buffered data.
Dim ReturnStream As New MemoryStream()
' set up the stream
Dim sw As New StreamWriter(ReturnStream)
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Try
'Get the sql string
Dim strSql As New StringBuilder()
strSql.Append("SELECT DISTINCT ISNULL blah, blah)
' connect to db
conn = New SqlConnection(ConnectionString)
conn.Open()
cmd = New SqlCommand(strSql.ToString, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
' get row names
Dim strTmp As String = ""
Dim counter As Integer
If dr.Read Then
For counter = 0 To dr.FieldCount - 1
If Not dr.IsDBNull(counter) Then
strTmp += dr.GetName(counter) & vbTab
Else
strTmp += "" & vbTab
End If
Next
End If
sw.WriteLine(strTmp)
' get the data
While dr.Read
strTmp = ""
For counter = 0 To dr.FieldCount - 1
If Not dr.IsDBNull(counter) Then
strTmp += dr.GetValue(counter) & vbTab
Else
strTmp += "" & vbTab
End If
Next
sw.WriteLine(strTmp)
End While
Catch exc As SqlException
Response.Write("SQL Error Occured: " & exc.ToString)
Catch exc As Exception
Response.Write("Error Occured: " & exc.ToString)
Finally
If Not dr Is Nothing Then
dr.Close()
End If
conn.Close()
'close up shop
sw.Flush()
sw.Close()
conn.Close()
End Try
' return link to stream
Return ReturnStream
End Function
memorystream so that, later on, a user can save the data as an xml file.
Our question is, how hard is this on our server? What if we have a meg
of data? Will that take up a meg of ram?
Can this bring the server to its knees? How easily?
Function getMemStream() As MemoryStream
'MemoryStream ReturnStream = new MemoryStream();
'Create the return memorystream object that will hold
'the buffered data.
Dim ReturnStream As New MemoryStream()
' set up the stream
Dim sw As New StreamWriter(ReturnStream)
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Try
'Get the sql string
Dim strSql As New StringBuilder()
strSql.Append("SELECT DISTINCT ISNULL blah, blah)
' connect to db
conn = New SqlConnection(ConnectionString)
conn.Open()
cmd = New SqlCommand(strSql.ToString, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
' get row names
Dim strTmp As String = ""
Dim counter As Integer
If dr.Read Then
For counter = 0 To dr.FieldCount - 1
If Not dr.IsDBNull(counter) Then
strTmp += dr.GetName(counter) & vbTab
Else
strTmp += "" & vbTab
End If
Next
End If
sw.WriteLine(strTmp)
' get the data
While dr.Read
strTmp = ""
For counter = 0 To dr.FieldCount - 1
If Not dr.IsDBNull(counter) Then
strTmp += dr.GetValue(counter) & vbTab
Else
strTmp += "" & vbTab
End If
Next
sw.WriteLine(strTmp)
End While
Catch exc As SqlException
Response.Write("SQL Error Occured: " & exc.ToString)
Catch exc As Exception
Response.Write("Error Occured: " & exc.ToString)
Finally
If Not dr Is Nothing Then
dr.Close()
End If
conn.Close()
'close up shop
sw.Flush()
sw.Close()
conn.Close()
End Try
' return link to stream
Return ReturnStream
End Function