|
Hi,
I am a newbie to SQL and all I know is insert, delete and update
I have to upload some resources (images and files) to the database. For this purpose I have created a column with datatype varbinary and length 8000.
But I have some problems in this process :
1. Is there any way that we can upload files of size more then 8000 ?
2. I tried uploading a file of size 2393 KB on disk. But I get the following error:
System.Data.SqlClient.SqlException: Cannot create a row of size 8077 which is greater than the allowable maximum of 8060.
This is how I create the byte array :
FileStream fs = new FileStream(aFilePath, FileMode.Open);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length );
fs.Close();
this is how I upload to db :
SqlParameter sqlParam = new SqlParameter("@" + fieldName, sqlDbType.VarBinary, 8000);
sqlParam.Value = buffer;
mySqlCommand.Add(sqlParam);
mySqlCommand.ExecuteNonQuery();
Sorry, the above code is in bits and pieces since I cannot put all here...
Please help me...
Cheers
CNU
|
|
|
|
|
|
Thanks a lot...
I changed the sqlparameter staement by removing the size. It is working now.
But I have another problem....
This is how I am displaying the downloaded image on a lable.
System.IO.MemoryStream ms = new MemoryStream();
ms.Write(byteArray, 0, byteArray.Length);
ms.Flush();
this.lblImage.Image = System.Drawing.Image.FromStream(ms);
ms.Close();
The exception is as follows:
System.ArgumentException: Invalid parameter used.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)
at System.Drawing.Image.FromStream(Stream stream)
at InitBasicInfo() in d:\projects\tc project\tcstudio\frmservermodel.cs:line 769
Thanks.
Cheers
CNU
|
|
|
|
|
You are trying to hard to construct your MemoryStream! This works just fine:
System.IO.MemoryStream ms = new MemoryStream(byteArray);
As a sidenote, ms.Flush() is overriden to do nothing at all.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
I have an expereince similar to you. But what I have don't is working with access database. I go the tip from my teacher that don't store an object (if you want to store an image/picture) in your database. Because it would increase a lot of space when your record increase. The best way to do this just create a field with text string and hold the path that point to the picture file. When you load the record on the form just load the picture in the picture box base on the path that you store in the database. This will decrease a lot of space from your database and improve a lot of database performance. I also test it and it is work very well.
But remember! if you use the method from me, becareful when you image is change it file name or file path. You have to handle the RUN TIME error in your application to do that.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Hi all,
Why wont my sql query work.
It returns with no records.
SELECT pkey, description
FROM Test
WHERE (((test.description) Like 'DEL%'))
Yet there is a record with 'DELIVER' in the description col of the Test table.
Tnx
|
|
|
|
|
Try testing it with the SQL builder
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
Test your query in Query Analyzer.
By the way those parenthesis are extra
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
I have been trying to get some batch files to create and show tables details, but the only file I can get to work is one that populates a table;
i.e. load data local infile C:\\mysql\\data\\testDB\\data.sql"
I have created a few batch files as follows:-
File 1 (creatTest.sql)
CREATE TABLE Test(name varchar(15), price float(6,12)); and
File 2 (showTables.sql)
show tables; If I now try and run the showTables.sql batch file: e.g
mysql> source showTables;
I get error 2 if I miss out the path or
this gives the error Unknown command '\\' (for each '\\') if I use
mysql> source C:\\mysql\data\\mydb\\showTable.sql;
Is it possible to create/run batch files and are they any good examples (for Windows) please!
Does anyone have sample batch files to run for mySQL 4.1 in a Windows environment.
|
|
|
|
|
Are you saying that the SQL Server is on another machine, or the same machine?
You can generally specify a host name for the server, and your client having a static or dynamic IP is largely irrelevant, providing the name can be resolved (relies on either DNS or HOSTS lookup), and there is a network path available.
Is it possible that there's a firewall in the way which is blocking the SQL Server port?
Steve S
Developer for hire
|
|
|
|
|
Try to check the connection library[^] for the method that you should be connect to your SQL server database. On the other hand, your application should be able to give an opportunity for the user to type in the database server that you database reside on. This method could be reduce an error in your application.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Hi,
I'm writing an windows application that access SQL SERVER database. But I have a problem when trying to run the program in a computer which has an internet connection with dynamic IP, it can't connect to the SQL database.
Is anyone have solutions for this problem?
thanks b4
|
|
|
|
|
i`m looking information about progress database, anybody ever use it? What kind of database is it? I`ve look it at google, but couldn`t find what I need. Thanks
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
|
Hi all,
Help – to be honest I’m not sure if this is an oracle question or a .net one, I am trying to invoke a job in my oracle 9i db from a web app. The job is created fine and runs fine when scheduled in oem. However I want to run the job from my vb.net web app. I have imported a dll, oemjobcreator, and invoked the Run command passing in what I believe to be the correct parameters but the job does not run. How do I invoke the job, or define the schedule from code? Has anyone tackled the problem of invoking oracle jobs from code?
Cheers,
Rob
|
|
|
|
|
I'm trying to insert a Hashtable in my database, and the way I found was first to serialize the Hashtable to a file before inserting the file (as a BLOB) into the database.
Is there a direct way to do this? That instead of going Object->File->BLOB, I can go from Object to BLOB directly.
Rafferty
|
|
|
|
|
Depends what your programming platform is. For instance, in C++ using OLE DB, you could serialise to an IStream object (or to memory and then create a stream on it), and use the IStream object directly from the provider...
Steve S
Developer for hire
|
|
|
|
|
oh yeah.. i'm using C#
I thought of a way that I'm not sure if it's going to work. This is how it goes:
- use the MemoryStream class
- Serialize the HashTable object to it using the BinaryFormatter.Serialize(...)
- Then convert this to type byte[] (the size of the byte array is based on the MemoryStream.Length <-- this is what I'm not sure of if this will work). Any feedbacks?
Thank you,
Rafferty
|
|
|
|
|
Can't help you, I'm afraid. I've used C++ almost exclusively for that kind of stuff. However, it sounds like it should work, since it's similar to what I've done. Presumably you have some way of writing arbitrary binary data to the db, specifying the data (your byte []) and the length, in which case, there's no reason to suppose it won't work.
Steve S
Developer for hire
|
|
|
|
|
I'll try to summarize what i did for inserting and for retrieving the BLOBs in a pseudo-code level...
object obj1;<br />
object obj2;<br />
object obj3;<br />
<br />
InsertData()<br />
{<br />
MemoryStream stream = new MemoryStream();<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
<br />
Hashtable ht = new Hashtable();<br />
ht.Add( "Object1", obj1 );<br />
ht.Add( "Object2", obj2 );<br />
ht.Add( "Object3", obj3 );<br />
<br />
formatter.Serialize( stream, ht );<br />
<br />
int iStreamLength = Convert.ToInt32(stream.Length);<br />
byte[] byteBackup = new byte[iStreamLength];<br />
stream.Read( byteBackup, 0, iStreamLength );<br />
stream.Close();<br />
<br />
SqlConnection conn = new SqlConnection( strConnectionString );<br />
SqlCommand cmd = new SqlCommand( "ins_BackupData", conn );<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.Parameters.Add( "@Name", "ObjectsBackup" );<br />
cmd.Parameters.Add( "@Data", byteBackup );<br />
<br />
cmd.ExecuteNonQuery();<br />
}<br />
<br />
RetrieveData()<br />
{<br />
SqlConnection conn = new SqlConnection( strConnectionString );<br />
SqlCommand cmd = new SqlCommand( "get_BackupData", conn );<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.Parameters.Add( "@Name", "ObjectsBackup" );<br />
<br />
conn.Open();<br />
<br />
object obj = cmd.ExecuteScalar();<br />
<br />
if( obj != null )<br />
{<br />
byte[] byteBackup = (byte[])obj;<br />
MemoryStream stream = new MemoryStream(byteBackup);<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
<br />
Hashtable ht = (Hashtable)formatter.Deserialize( stream );<br />
obj1 = ht["Object1"];<br />
obj2 = ht["Object2"];<br />
obj3 = ht["Object3"];<br />
<br />
stream.Close();<br />
}<br />
}
But in retrieving the data I'm getting this error, so clearly there's something wrong. I wonder if it's with the insertion or retrieval or both.
ERROR:
Binary stream does not contain a valid BinaryHeader, 0 possible causes, invalid stream or object version change between serialization and deserialization.
Any ideas? did I deserialize this incorrectly?
|
|
|
|
|
Hi
Frankly speaking, what ever one says, Microsoft technologies will always remain problem-matic.. specially with versions... they don have seamless integration. Deployment is always always an issue. But I still love .NET!! Anyway folks, my problem goes like this...
I am reading and updating excel sheet using ADO .NET.
Everything is working fine on machine, but on server it is all messing up...
I connect to sheet using the string called...
Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES;'
But whenver I try to execute insert command, following error occurs...
Operation must use an updateable query.Microsoft JET Database Engine at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at MyPledge.ClientPaymentData.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Web1\Data.aspx.vb:line 74
I will highly appreciate if someone help me... !!!
eff_kay
-------------------
Therez No Place like ... 127.0.0.1
|
|
|
|
|
Hi
Presently i'm working in VB.Net with Oracle 9i as Backend. I need to
insert a bulk of records with two columns one as varchar and other as
number.Need to call a procedure with string array and number array as
input parameter, where i could go for inserting into Table instead of
calling reader from codebehind class as number of times the array length.
Thanks in advance for you replies
|
|
|
|
|
I am trying to import records in a Access Database. Each time I run this code, the records are added to my database, BUT it adds to the existing database. Example if I run code once, it imports 100 records, the next time I run the code again, it imports another 100 records. Now my Access database has 200 records, when it should only have 100 records. Can anyone help me on this? Thanks
Private Sub ImportToAccess()
Dim Con1 As New ADODB.Connection
Dim Con2 As New ADODB.Connection
Dim mySQL1 As String
Dim mySQL2 As String
Dim myDSN As String
Dim mySET As String
Dim tmpTable As String
'Connection parameters for Source Database
myDSN = "DSN=Springbrook1;UID=suresh;PWD=nissan;"
mySET = "set schema 'pub'"
mySQL2 = "select * from customer"
'Open Source Database
Con2.Open myDSN
Con2.Execute (mySET)
'Open Destination Database
Con1.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Temp\VB Sample Codes\mcwd\Connect Program\test1.mdb;" & _
"Jet OLEDB:Engine Type=5;"
'WORKS BUT CREATES DUPLICATE RECORDS
'mySQL1 = "INSERT INTO [C:\Temp\VB Sample Codes\mcwd\Connect Program\test1.mdb].[tblCustomer] SELECT Cust_No, First_Name FROM [odbc;DSN=Springbrook1;UID=suresh;PWD=nissan;].[Customer]"
Con1.Execute mySQL1
Con1.Close
Con2.Close
Set Con1 = Nothing
Set Con2 = Nothing
End Sub
|
|
|
|
|
If your intention is to replace the existing set of records with the new set, then execute a delete statement before executing your insert statement... something like this:
Con1.Execute "DELETE FROM tblCustomer"
|
|
|
|
|
Since the table has linked information, Can I not use any other SQL statement to update the information into my table. Using the delete statement will empty my table before importing new records. Any other ways to update instead of delete?
Thanks
|
|
|
|