06-08-19, 02:58 PM
عند ادراج صورة علي هيئة binary لقاعدة بيانات سيكول.يحدث مشكله ويعطي timeout في حالة ان كان حجم الصورة اكثر من 12 كيلوبايت علي الرغم من اني استخدم حجم حقل
varbinary(max)
varbinary(max)
Dim CMD As SqlCommand
CMD = New SqlCommand("update T_NAMES set c_names_image=@c_names_image where c_names_id='" & NAMES_id_code.Trim & "'", SQLCLIENTCN)
CMD.Parameters.Add(New SqlClient.SqlParameter("@c_names_image", SqlDbType.Image)).Value = imgToByteConverter(PictureBox1.Image)
CMD.ExecuteNonQuery()
CMD.Dispose()'convert image to bytearray
Public Function imgToByteConverter(ByVal inImg As Image) As Byte()
Dim imgCon As New ImageConverter()
Return DirectCast(imgCon.ConvertTo(inImg, GetType(Byte())), Byte())
End Function'convert bytearray to image
Public Function byteArrayToImage(ByVal byteArrayIn As Byte()) As Image
Using mStream As New MemoryStream(byteArrayIn)
Return New Bitmap(Image.FromStream(mStream))
End Using
End FunctionTry
Dim ms As New MemoryStream
Dim arrimage() As Byte = {0}
If (Pic.Image IsNot Nothing) Then
Pic.Image.Save(ms, Pic.Image.RawFormat)
arrimage = ms.GetBuffer
ms.Close()
End If
Dim strsql As String
Dim acscmd As New SqlCommand
' Dim con As New SqlConnection
Dim con As New SqlConnection
If IO.File.Exists(Application.StartupPath & "\DATABASE\bak2019.mdf") Then
If My.Settings.constr = "" Then
con = New SqlConnection(("Data source=.\SQLEXPRESS;AttachDbFilename= " & Application.StartupPath & "\DATABASE\bak2019.mdf;Integrated Security=True;User Instance=True"))
Else
If IO.File.Exists(My.Settings.constr) Then
con = New SqlConnection(("Data source=.\SQLEXPRESS;AttachDbFilename= " & Application.StartupPath & "\DATABASE\bak2019.mdf;Integrated Security=True;User Instance=True"))
Else
If MessageBox.Show("هل تريد تحديد مسار قاعدة البيانات", "خطأ قاعدة البيانات غير موجودة", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign) = DialogResult.Yes Then
Database.Show()
Else
MessageBox.Show("سيتم استخدام قاعدة البيانات الحالية ", "تنويه", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
con = New SqlConnection(("Data source=.\SQLEXPRESS;AttachDbFilename= " & Application.StartupPath & "\DATABASE\bak2019.mdf;Integrated Security=True;User Instance=True"))
End If
End If
End If
Else
MessageBox.Show("قاعدة البيانات غير موجودة", "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
' Exit Function
End If
strsql = "update labdetails set itmnme=@itmnme,itmspecial=@itmspecial,itmadress=@itmadress,itmphone=@itmphone,itmtime=@itmtime,itmlogo=@itmlogo,itmprint=@itmprint,itmnameenglish=@itmnameenglish,itmspecialenglish=@itmspecialenglish,signature1=@signature1,signature2=@signature2"
acscmd.CommandText = strsql
acscmd.Connection = con
con.Open()
acscmd.Parameters.AddWithValue("@itmnme", txtitmname.Text)
acscmd.Parameters.AddWithValue("@itmspecial", txtspeciality.Text)
acscmd.Parameters.AddWithValue("@itmadress", txtadress.Text)
acscmd.Parameters.AddWithValue("@itmphone", txtphone.Text)
acscmd.Parameters.AddWithValue("@itmtime", txttime.Text)
acscmd.Parameters.AddWithValue("@itmlogo", IIf(Pic.Image IsNot Nothing, arrimage, DBNull.Value))
acscmd.Parameters.AddWithValue("@itmprint", printchck.Checked)
acscmd.Parameters.AddWithValue("@itmnameenglish", Txtitm.Text)
acscmd.Parameters.AddWithValue("@itmspecialenglish", txtspecial.Text)
acscmd.Parameters.AddWithValue("@signature1", txtsign1.Text)
acscmd.Parameters.AddWithValue("@signature2", txtsign2.Text)
acscmd.ExecuteNonQuery()
acscmd.Dispose()
con.Close()
con.Dispose()
Me.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try