|
Create both connection and server object before you start the thread, and pass them as arguments to the new thread. This way you'll have a reference to both objects. Either lock the object or synchronize before accessing it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have an windows form application with multiple forms. If I open two of these forms in a runtime, I receive this error:
An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
If there is a handler for this exception, the program may be safely continued.
The idea is that I don't have any programs that consume so much memory and this error occurs only after I introduced in script a background worker. It can cause this problem?
|
|
|
|
|
OutOfMemory probably wouldn't cause this. But you know the drill, debug it. What exactly causes it (not circumstances, but specific action being executed in code)? Does it still happen if the work that the background worker does is executed on the main thread?
|
|
|
|
|
Dear Friends,
I have doubt in TPL. When I'm Trying To Break Down List into Multiple List and Save This Data into Single Table With the Use Of TPL. Then It Generate Error: Database is Already Use.
How I manage This Database Connection because All the Element Of List Have Use Connection .
In My Sql Server only 4 connection have been open at same Time and TPL maxParallelism=4 Set by Me.
Please Suggest me Guys How can i Manage It
|
|
|
|
|
Without seeing the code you're talking about it's pretty much impossible to tell you what's going on.
|
|
|
|
|
Open your connection before you enter the Task, save the data using this single connection and then close the connection once the Task has completed.
|
|
|
|
|
Hi,
Really need help and guidance.
I need to pull data from server if there is available data, it shouldn't interrupt users action while data is being pulled.
Scenario:
Login to connect
Pull data if available
once complete, process
wait for the next data..
I tried different approach but failed. New to asynchronous
1. The link below is working but failed and timeout expired in the middle.
https://msdn.microsoft.com/en-us/library/bew39x2a(v=vs.110).aspx[^]
It's eating all my time.
Really Appreciate
Dabsukol
|
|
|
|
|
This sounds like an ideal job for Rx. If I were you, that's the avenue I would explore.
|
|
|
|
|
A very simple one would be to create a task and run it,
Task.Run(async () =>
{
});
Otherwise, you can always consider using asynchronous programming model[^]. In which you create methods, functions with async modifiers and then use the awaits to continue processing until the work (job, whatever) has been done.
public async void getData(){
app.IntVariable = await server.GetDataAsync();
}
Also, since the error is Time out I would suggest that you configure your server also. There may be a problem with that, Timeout would occur regardless of async or sync programming being used.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
dabuskol wrote: it shouldn't interrupt users action while data is being pulled. What kind of app is it? WinForms, WPF, web, mobile?
/ravi
|
|
|
|
|
It is a window service. It will run in the background and pull data from the server then save to the databse.
My Client program will read the updated value from DB
Dabsukol
|
|
|
|
|
|
Hi, I am a beginner c# programmer and still having problems with my DataReader.
I searched and tried several codes but no positive result.
So I decided to post some parts from my sql, asp, cs code project.
The problem area is commented //.
I would be very greatful if anyone helped me giving specific recomendation how to fix that issue.
===========================================================
CREATE TABLE `images`
(
`Image_ID` int(32) NOT NULL AUTO_INCREMENT,
`Image` blob,
PRIMARY KEY (`Image_ID`)
)
ENGINE=InnoDB AUTO_INCREMENT=3608 DEFAULT CHARSET=binary;
============================================================
CREATE TABLE `groups`
(
`Group_ID` char(02) NOT NULL,
`Number` varchar(5) DEFAULT NULL,
PRIMARY KEY (`Group_ID`)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8;
============================================================
CREATE TABLE `register`
(
`ID` int(32) NOT NULL AUTO_INCREMENT,
`Arrive_Img_ID` int(32) DEFAULT NULL,
`Leave_Img_ID` int(32) DEFAULT NULL,
`Students_ID` char(2) DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `FK_register_ArriveImg` (`Arrive_Img_ID`),
KEY `FK_register_LeaveImg` (`Leave_Img_ID`),
KEY `FK_register_Students` (`Students_ID`),
KEY `Date` (`Date`),
CONSTRAINT `FK_register_ArriveImg` FOREIGN KEY (`Arrive_Img_ID`) REFERENCES `images` (`Image_ID`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `FK_register_LeaveImg` FOREIGN KEY (`Leave_Img_ID`) REFERENCES `images` (`Image_ID`) ON DELETE SET NULL ON UPDATE SET NULL,
CONSTRAINT `FK_register_Students` FOREIGN KEY (`Students_ID`) REFERENCES `students` (`Students_ID`) ON DELETE CASCADE ON UPDATE CASCADE
)
ENGINE=InnoDB AUTO_INCREMENT=2248 DEFAULT CHARSET=utf8;
==============================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImageRetrieve.aspx.cs" Inherits="ImageRetrieve" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 389px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<br />
<br />
<br />
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:DropDownList ID="ddlGroup" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlGroup1_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">
<asp:DropDownList ID="ddlName" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlName_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td>
<asp:GridView ID="gvImages" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="OnRowDataBound" Width="105px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Image_ID" HeaderText="Image_ID" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="80" Width="80" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</td>
</tr>
</table>
<br />
</form>
</body>
</html>
====================================================================================================
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ImageRetrieve : System.Web.UI.Page
{
string constr = "Data Source=localhost;port=3306;Initial Catalog=test;User Id=root;password=2525";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGroupdropdown();
}
}
protected void BindGroupdropdown()
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select * from groups", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlGroup.DataSource = ds;
ddlGroup.DataTextField = "Number";
ddlGroup.DataValueField = "Number";
ddlGroup.DataBind();
ddlGroup.Items.Insert(0, new ListItem("--Select--", "0"));
ddlName.Items.Insert(0, new ListItem("--Select--", "0"));
}
private string getGroupID()
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select Group_ID from groups where Number='" + ddlGroup.SelectedValue + "'", con);
string appid = (cmd.ExecuteScalar() ?? String.Empty).ToString();
con.Close();
return appid;
}
protected void ddlGroup1_SelectedIndexChanged(object sender, EventArgs e)
{
string aid = getGroupID();
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("select CONCAT(SurName , ' ', Name , ' ', MiddleName) AS SNM from students where Group_ID='" + aid + "'", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlName.DataSource = ds;
ddlName.DataTextField = "SNM";
ddlName.DataValueField = "SNM";
ddlName.DataBind();
ddlName.Items.Insert(0, new ListItem("--Select--", "0"));
BindGrid();
}
private string getStudent_ID()
{
var SNM = ddlName.Text.Replace("'", "''");
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("Select Students_ID from students where CONCAT(SurName , ' ', Name , ' ', MiddleName)='" + SNM + "'");
cmd.Connection = con;
String s = (cmd.ExecuteScalar() ?? String.Empty).ToString();
con.Close();
return s;
}
private void BindGrid()
{
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("SELECT Image_ID, Image FROM images where Image_ID='" + getImage_ID() + "'", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
gvImages.DataSource = dt;
gvImages.DataBind();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
byte[] bytes = (byte[])(e.Row.DataItem as DataRowView)["Image"];
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
(e.Row.FindControl("Image1") as Image).ImageUrl = "data:image/png;base64," + base64String;
}
}
private string getImage_ID()
{
MySqlConnection con = new MySqlConnection(constr);
con.Open();
MySqlCommand cmd = new MySqlCommand("Select Arrive_Img_ID,Leave_Img_ID from register where Students_ID='" + getStudent_ID() + "'");
cmd.Connection = con;
MySqlDataReader reader = cmd.ExecuteReader();
//Here I can't find suitable code to call multiple results from register table.
//return s;
}
protected void ddlName_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid();
}
}
|
|
|
|
|
For starters, never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Then just use your reader object:
while(reader.Read())
{
Console.WriteLine(reader["Arrive_img_ID"]);
Console.WriteLine(reader["Leave_img_ID"]);
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I want to import documents from the scanner in my MVC web application and use optical character recognition to fetch the data.
I am not willing to use any expensive libraries like TWAIN, dynamsoft, Atalasoft, LeadTools, Asprise, etc..
I looked for Microsoft OCR, but it seems the library only works for Windows Store Apps.
Please suggest me some good yet free/cheap library for scanning and OCR in MVC web application.
|
|
|
|
|
The server can't access hardware on the client. If you're googling for OCR libraries that can be used with MVC you're not going to find anything.
|
|
|
|
|
You could try Tesseract. A .NET wrapper is available here[^].
/ravi
|
|
|
|
|
Can you provide me with bit more details about Tesseract for .net. Didn't get much documentation about it.
|
|
|
|
|
See this[^] link for instructions.
/ravi
|
|
|
|
|
when i extracted BLOB data from database i can see like this in my word doc.
how to convert it to readable format?
o � 8 A+ ¬ 2
e �
o � ¬ 2
e
o � Cleveland, OH : & + & % / . H F
2
e ( o � �) � o ' �� � �� � @ Garamond - 2 2
� P o � Management Trainee ProgramZ 0 7 0 6 / S /
|
|
|
|
|
That depends on what it is!
If it's a Word document, then save it as a .DOC or .DOCX file, and get Word to open it. Presumably, when you saved the data you also saved a file name with it?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Yes correct..i am saving it as .DOC
when i am opening, it is asking conversion from "Encoding text" and when i select "Unicode" it is displaying like that
|
|
|
|
|
Try an experiment: upload a known-working file, and then save it as a different name. Compare the two and see if there are any differences.
If there are, then you need to start by looking at how you are storing it and make sure that works first.
But...DOC files aren't all Unicode - they can be a binary format, so doing an Unicode conversion is probably going to mess them up.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Chances are that even inside your Word document and this web page there are many things that messed up the format, made it even worse.
The binary object that you captured was indeed an array of bytes containing the data (I won't say it was initially a Word document) with a format to be taken care of while converting back to a valid file. That is why whenever you store a file in the image type (in SQL image is the binary data, not the image you know) you also store the file extension or MIME type (the thing you know as "application/json" etc.). They are used to convert that data back to files.
When you copied the data, it was not of Word format, every file has its own structure that is followed when converting the bytes back to a representation of the file. Word was not able to convert it back to actual representation, in which case it showed you that broken format.
Notice that most of the content, such as those characters were easily mapped and thus they were shown to you, but a few other stuff was not mapped. Simple as that.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Ya correct..few content not mapped and some of the content mapped..tried dfferent options from Word ponit of view..but no luck
|
|
|
|