MVC EF String Length / Data Type for Signature Image - asp.net-mvc

I'm using a javascript plugin called jSignature to give my MVC4 application delivery signature capture functionality. jSignature outputs the signature info in a data:image/png;base64,iVBORw0KG... string format that looks to be around 32,000 characters long. I created a property in my model called DeliverySignature as a string and am able to save and retrieve the signature data but when I pull it back in from the database it's only about 5,000 characters long. What data type do I need to be using in my model's definition and in the action method (it's being passed in to a controller to save to the db) so that it preservers the complete string length? Thank you.

I would store it in varchar(max) column.
You can keep model property type of string as strings do not have a limited length.

Related

F# type provider

My project handles data that is stored in a key value based NoSQL database.The value part is stored as byte stream.I want a type provider to read my data according to the schema of the byte stream.The schema of the data is represented as json schema. Can I use Json type provider to read this data? If no then what can be the solution to my problem?
If your DB stores the JSON as a bytestream, simply decode it through System.Text.Encoding.UTF8.GetString (replace UTF8 with the appropriate encoding if necessary) in order to get the JSON as a regular string.
Then, you can use the JSON type provider on that stream like on any other stream, as long as you provide a compile-time sample for the type provider to use. A schema doesn't work.
In other words, you need to extract a fully representative sample of your database's JSON contents, then declare the provided types using that sample, either as a string directly embedded in the code, or as a file URI that your development machine can access.
As long as the sample matches the actual structure of your database, it will work at run-time.
// embedded in the code
type Simple1 = JsonProvider<""" { "name":"John", "age":94 } """>
// referenced
type Simple2 = JsonProvider<#"C:\MyProjectFolder\sample.json">

Array in view mvc

I have an array of bytes in my model
public byte[] created_dt { get; set; }
It represents a timestamp value in the database.
In my view , I am referring it as #model.created_dt
but it is coming as system.byte[]
How to resolve this?
Try as this is just an example to achieve the functionality
#foreach(var a in model.created_dt){
<label>#a</label>
}
Judging by the behavior, this looks like ASP.NET and you are simply seeing the output of an implicit call to ToString() on the array (the default way of displaying anything that does not have a template defined). You will have to do something with the raw byte data and present it to the user.
Since you refer to "timestamp" and the property name might suggest a record creation time, you may want to write a helper method to translate this raw data to a DateTime which you could then format accordingly.
However, one of the following is most likely true:
It strikes me as odd that you are using raw binary to store what should otherwise be a datetime2 column. (Or it is a datetime in your database but you're doing something unorthodox to retrieve the value.)
Your property/column name of "created_dt" is a misnomer and it is really a timestamp (i.e. rowversion) column. In which case I don't think this is something a user would know what to do with, and it probably doesn't belong on the UI.

Convert any record to a string and back?

How can I convert any record type to a single String and back? Perhaps load the record into a stream and read it as a String? The records I'm using won't have any special types included - they're just using simple things like String, Integer, PChar, DWORD, and Array of [String], etc. and nothing like classes or functions.
This string will further be saved into various places, such as a flat text file, database record, sent over the network, etc. The string contents may be transferred by other means between each of these, such as copying the string from a text file and saving it to a database record. The general idea is that the string will be compatible enough to save anywhere, move it around, and load it back in to its original state. I do understand I need to be able to recognize what type of record it is and assign it accordingly, and that part I don't need help with.
You can serialize your record using the RTTI, from here you can use XML, JSON or other format to persist the record data.
If you don't want write your own method to serialize the records try these alternatives.
superobject (using the TSuperRttiContext class you can serialize a record to JSON)
TKBDynamic
SynCommons unit from Synopse.
XmlSerial unit (Object and Record Serialization and De-serialization to XML) from Robert Love

Problem with SaveChange() in Entity Framework Data model

I am facing a problem with the SaveChanges() method in Entity Framework. Sometimes it works fine and sometimes it's not instead I get an error message saying:
String or binary data would be
truncated. The statement has been
terminated.
Can any one help me with this ....
thanks.
By default all strings stored as NVARCHAR(4000). In case while string length above 4000 chars you get this error. To limit field length and add validation logics to your model use StringLength(...maxlen...) attribute (http://msdn.microsoft.com/en-US/library/system.componentmodel.dataannotations.stringlengthattribute.aspx) with your model properties.
you can correct this problem on Data base Table on
"nvarchar" and "varchar Columns " that you increase Lenght of Column on your Table
also
when you insert or Update with EF , you can check len of value and check your query With
SQL Profiler when you call SaveChanges()method
and you check your value in GET and SET methods on Domain Layer or Entities that EF get you
and below link is Useful :
EF Exception: String or binary data would be truncated. The statement has been terminated.?
,
http://forums.asp.net/t/1660868.aspx/1

Calling stored procedure with a fixed length binary parameter using Entity Framework

I have a problem calling stored procedures with a fixed length binary parameter using Entity Framework. The stored procedure ends up being called with 8000 bytes of data no matter what size byte array I use to call the function import. To give some example, this is the code I am using.
byte[] cookie = new byte[32];
byte[] data = new byte[2];
entities.Insert("param1", "param2", cookie, data);
The parameters are nvarchar(50), nvarchar(50), binary(32), varbinary(2000)
When I run the code through SQL profiler, I get this result.
exec [dbo].[Insert] #param1=N'param1',#param2=N'param2',#cookie=0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
[SNIP because of 16000 zeros]
,#data=0x0000
All parameters went through ok other than the binary(32) cookie. The varbinary(2000) seemed to work fine and the correct length was maintained.
Is there a way to prevent the extra data being sent to SQL server? This seems like a big waste of network resource.
Use varbinary instead of binary. Helpfull for me
EF 4 always uses largish params, because using param-size = data-size mostly means that the query can't be re-used with new param values, so SQL can't cache the queries for you. In other words, what it's doing now is probably more efficient overall than using a smaller param, if your data size ever changes.
If your data size never changes, then use a different column width.

Resources