|
Hi! I'm going mad on this and don't know how to solve it...
I have a class ExecQuery which executes a SQL Script:
public LoadScreen ldScreen = null; //the LoadScreen class
public ExecQuery(ldScreen ld)
{
ldScreen = ld;
}
public void ececute()
{
conn = new SqlConnection(conString);
server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script); //script is my textfile
}
Now while this executes I'm showing a loading screen with a cancel button. When I hit the button I call an event in my LoadScreen class:
private void cancel_Click(object sender, EventArgs e)
{
ExecQuery exec = new ExecQuery(this);
if (InvokeRequired)
{
BeginInvoke(new MethodInvoker(delegate() { exec.cancelProcess(); }));
}
else
{
exec.cancelProcess();
}
}
This takes me right back to my ExecQuery class and to the method:
public void cancelProcess()
{
server.ConnectionContext.Cancel();
}
where I get a NullReference Exception because server is null. I know why this happens. I shouldn't make that instance of the ExecQuery class at one point but I don't know how to solve this. I tried workarounds and nothing works.
How to get the server variable from the loading screen (which opens before the server variable gets a value)?
|
|
|
|
|
Why not just check the server variable, and if it is null take a different path?
|
|
|
|
|
What a different path? I need to access the connection to cancel it.
|
|
|
|
|
Well I don't know how all your code is put together, so you need to work it out for yourself. If the server variable has not been set, then what else can you do to cancel the connection?
|
|
|
|
|
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...
|
|
|
|