Ohh...
Schreibst du wirklich die ganze datei in einen string??
Lass Dir das mal ausgeben:
string.Format(Sql.INS_FILE,fileName, fileData, contentType, fileData.Length)
Empfehlenswerter w�re es, das mit Parametrisierten Abfragen zu machen
Claudius
> Hallo zusammen
>
> Ich habe heute versucht ein File-Uploadscript zu schreiben,
> welches Files direkt in eine MSSQL Datenbank und auch in
> einen Ordner auf dem Server schreibt. Das schreiben in den
> Ordner klappt und auch beim schreiben in die Datenbank kommt
> keine Fehlermeldung. Beim auslesen aus der Datenbank hingegen
> wird immer ein File von 13 Bytes an den Browser gesandt, egal
> wie gross es beim Upload war. Ich hab leider auch nicht
> herausgefunden wie ich herausfinden kann ob �berhaupt alles
> erfolgreich in die DB geschrieben wurde, auch nicht mit dem
> MSSQL Enterprise Manager.
>
> Es stellt sich auch die Frage ob ich die richtigen Feldtypen
> verwendet habe, f�r die Byte[]-Daten (Spalte: filedata) habe
> ich den Feldtyp "image" mit L�nge 16 ausgew�hlt.
>
> Und so sieht mein Upload-Script aus:
>
> //************************************************************
> *********
> //Uploads file to server
> protected void btnUpload_ServerClick(object sender,
> System.EventArgs e) { HttpPostedFile file = txtAttachment.PostedFile;
>
> if (file !=null)
> {
> //Gets filename
> string fileName= Path.GetFileName(file.FileName);
>
> //Gets contenttype
> string contentType= file.ContentType ;
>
> //Gets filesize
> int fileSize= file.ContentLength;
>
> //Writes bytes into byte array
> byte[] fileData = new byte[fileSize];
> file.InputStream.Read(fileData, 0, fileSize);
>
> this.WriteToFile(Server.MapPath(".\\" + "files\\" +
> fileName), ref fileData); this.WriteToDB(fileName,
> contentType, ref fileData); } }
>
> //************************************************************
> *********
> // Writes file to current folder
> private void WriteToFile(string strPath, ref byte[] fileData)
> { // Create a file FileStream newFile = new
> FileStream(strPath, FileMode.Create);
>
> // Write data to the file
> newFile.Write(fileData, 0, fileData.Length);
>
> // Close file
> newFile.Close();
> }
>
> //************************************************************
> *********
> //Writes file to the DB
> private void WriteToDB(string fileName, string contentType, ref byte[]
> fileData)
> {
> //Creates connection
> SqlConnection sqlConn = new SqlConnection( "server=" +
> Const.DATABASE + ";initial catalog=" + Const.INITIALCATALOG +
> ";user id=" + Const.USERID + ";password=" + Const.PASSWORD);
>
> //Opens connection
> sqlConn.Open();
>
> //Creates query
> SqlCommand sqlCmd = new SqlCommand(
> string.Format(Sql.INS_FILE,fileName, fileData, contentType,
> fileData.Length), sqlConn);
>
> //Executes query
> sqlCmd.ExecuteNonQuery();
> }
>
> //************************************************************
> *********
> //************************************************************
> *********
> Das Downloadscript:
>
> private void Button1_Click(object sender, System.EventArgs e)
> { //Creates connection SqlConnection sqlConn = new
> SqlConnection("server=" + Const.DATABASE + ";initial
> catalog=" + Const.INITIALCATALOG + ";user id=" + Const.USERID
> + ";password=" + Const.PASSWORD);
>
> SqlDataAdapter sqlAdpt = new SqlDataAdapter();
> sqlAdpt.SelectCommand = new SqlCommand("SELECT * FROM
> tbl_files", sqlConn);
>
> //Fills dataset
> DataSet ds = new DataSet();
> sqlAdpt.Fill(ds, "tbl_files");
>
> //Testing, returns only first recordset
> DataRow row = ds.Tables["tbl_files"].Rows[0];
>
> //Sends header
> Response.Clear();
> Response.AddHeader("content-disposition","attachment;
> filename=" + (string)row["filename"]); Response.ContentType =
> (string)row["contenttype"];
> Response.BinaryWrite((byte[])row["filedata"]);
> Response.End();
> }
> //************************************************************
> *********
>
> Also, ihr seid meine letzte Hoffnung, es haben heute mehrere
> Personen versucht das Problem zu beheben - Leider ohne Erfolg.
>
> F�r jeglichen Art von Anregungen und L�sungsvorschl�ge bin
> ich dankbar.
>
> Viele Gr�sse Daniel
>
> _______________________________________________
> Asp.net Mailingliste, Postings senden an:
> [EMAIL PROTECTED]
> An-/Abmeldung und Suchfunktion unter:
> http://www.glengamoi.com/mailman/listinfo/asp.net
>
_______________________________________________
Asp.net Mailingliste, Postings senden an:
[EMAIL PROTECTED]
An-/Abmeldung und Suchfunktion unter:
http://www.glengamoi.com/mailman/listinfo/asp.net