locked
SQL Server 2000 File upload RRS feed

  • Question

  • User302303298 posted

    hi

    i am using VS2003 and .net 1.1. i need to upload a cert file into sql server 2000. code is as follows, i am not sure if this code is working or not, its not giving any error nor throwing any exception. in this function i am only converting ther .cer file to byte array. and in other function i am passing this byte to a stored procedure. in stored procedure i have declare a parameter as "@cert binary". i cant see the binary data in sql server 2000, its only showin <binary> in that column. i need to download this file now, how can i do that.

    Dim selectedCert As HttpPostedFile

    Dim certLength As Integer

    Dim isValid As Boolean = False

    'Dim imageType As String

    'Dim fileUpload As System.Web.UI.HtmlControls.HtmlInputFile = .FindControl("fileUpload")

    selectedCert = fileUpload.PostedFile

    certLength = selectedCert.ContentLength

    'imageType = selectedCert.ContentType

    Session.Add("isDefaultLogo", 0) ' To check if default logo is used

    If fileUpload.PostedFile.ContentLength = 0 Then

    ' DO NOTHING

    Else

    ReDim binaryCert(certLength - 1)

    'check if there a certificate file or not

    If (selectedCert.ContentLength = 0) Then

    ' DO SOMETHING

    Else

    selectedCert.InputStream.Position = 0

    selectedCert.InputStream.Read(binaryCert, 0, certLength - 1)

    Response.Write(selectedCert.ContentType.ToString)

    If (selectedCert.ContentType.ToLower <> "application/x-x509-ca-cert") Then

    lblMsg.Visible = True

    lblMsg.Text = "Only Certificate (*.cer) files are allowed."

    isValid = True

    Return False

    End If

    End If

    End If

    If isValid Then

    Try

    Dim strm As IO.FileStream = System.IO.File.Open(System.IO.Path.GetFullPath(fileUpload.PostedFile.FileName), IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite)ReDim binaryCert(strm.Length - 1)

    strm.Read(binaryCert, 0, strm.Length)

    strm.Close()

    Catch ex As Exception

    Return False

    End Try

    End If

     

    thnx in advance

    cheers

    Tuesday, October 9, 2007 6:55 AM

Answers

  • User-1727935884 posted

    Hi zeeshannasir,

    Based on my understanding, i'm afraid you will not be able to store that binary file into your sql2000 database. As far as i know, there is even no database connection in your code, so, how could you store that image file into sql 2000?

    I would suggest you read this article first, it tells you how to manipulate binary data with sql server. see: http://www.dbazine.com/sql/sql-articles/charran5

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 12, 2007 5:19 AM

All replies

  • User-1727935884 posted

    Hi zeeshannasir,

    Based on my understanding, i'm afraid you will not be able to store that binary file into your sql2000 database. As far as i know, there is even no database connection in your code, so, how could you store that image file into sql 2000?

    I would suggest you read this article first, it tells you how to manipulate binary data with sql server. see: http://www.dbazine.com/sql/sql-articles/charran5

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 12, 2007 5:19 AM
  • User302303298 posted

    Hi Bo Chen

    i hav removed that code myself, i am passing the value as parameter to stored procedure. i removed it to shorten the entry and thought its understood that i am doing DB connection and stuff . :-)

    any way i have already solved the problem and its working but not how i wanted it to be. maybe you can explain that problem :-). i was passing byte() to sql server, and in sql server column was of type binary. i dont know why but passing byte() to SProc doesn't work, but when i tried simple insert query, it worked. i spent 2 days on this issue but didnt' get it why SProc is not getting value of byte()

    regards

    Friday, October 12, 2007 7:05 AM
  • User-1727935884 posted

    Hi zeeshannasir,

    How did you pass those binary data to stored procedure? could you post your code here please, i can debug it for you. BTW, i used to use streadreader to read files and then store them to sql database, and it works. Also, read that article i suggested in my last post, i think it has some examples on how to manipulate binary data between your application and sql server.

    Hope my suggestion helps

    Sunday, October 14, 2007 10:35 PM