|
|
What is the format of a SQLConnection connection string that is passed in the constructor method? I have run a search engine search online and all I could find so far is examples like:
"Data Source=(local);Initial Catalog=AdventureWorks; Integrated Security=SSPI;";
"User Id=sa;Server=localhost;Initial Catalog=Test;"
The examples raises questions. Since the SQL Server Management Studio (SSMS) program offers a different set of fields during start up in order to connect to a database, I have to ask how does "Server type, "Server name", "Authentication", "User name" and "Password". Also, is "Catalog" another name for a database table?
|
|
|
|
|
|
i want to create table in RichTextBox.it is done using string builder class but i want to print this richtextbox table with other controls on a single report.Is it possible to print Richtextbox Table format with other controls ?
|
|
|
|
|
Most likely, yes. Assuming you know how to structure a printed page.
|
|
|
|
|
Hi,
Perhaps this article of Howard 9448490 here on CP is of some help:
A Simple RTF Print Form[^]
With friendly greetings,
Eric Goedhart
|
|
|
|
|
Hi, I inherited a program from a programmer that has since left the company. He built it with threading and the program crashes I think due to starting more threads than the system can handle. I am thinking that I need to implement a Thread Pool for this code, and am unsure how I should do that not having done it before, and complicating the matter of modifying the existing code.
So, here is the existing code that uses the threading;
using my.data;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading;
namespace CnaFirmware
{
public class DbUpdateFromField
{
Dictionary<string, CNA> cnas;
ConcurrentQueue<string> ConsoleQueue;
EventWaitHandle UpdateComplete;
ClsUdpDispatcher UdpDispatcher;
List<string> updates;
class CNA
{
public string ip;
public string firmware;
public int cktid;
public bool updated;
public bool error;
public CNA(string i, string f, int c)
{
this.ip = i;
this.firmware = f;
this.cktid = c;
this.updated = false;
this.error = false;
}
}
public DbUpdateFromField(ClsUdpDispatcher disp, ConcurrentQueue<string> q, EventWaitHandle op_done)
{
UdpDispatcher = disp;
ConsoleQueue = q;
UpdateComplete = op_done;
Log("start");
updates = new List<string>();
cnas = new Dictionary<string, CNA>();
new Thread(() => Start()).Start();
}
void Start()
{
GetIpList();
GetCnaData();
}
void Log(string s)
{
ConsoleQueue.Enqueue("DbUpdate: " + s);
}
void GetCnaData()
{
SqlConnection DB;
foreach (var v in cnas)
{
new Thread(() => GetCnaInfo(v.Value)).Start();
}
bool done;
do
{
Thread.Sleep(50);
done = true;
foreach (var v in cnas)
{
if (!v.Value.updated && !v.Value.error) done = false;
}
} while (!done);
if (updates.Count > 0)
{
Log(string.Format("Sending {0} updates to database...", updates.Count));
using (DB = new SqlConnection(Globals.ConnectionString))
{
try
{
DB.Open();
}
catch (Exception ex)
{
Log(ex.Message);
return;
}
try
{
using (SqlCommand sql = new SqlCommand())
{
sql.Connection = DB;
foreach (string query in updates)
{
sql.CommandText = query;
sql.ExecuteNonQuery();
Thread.Sleep(10);
}
}
}
catch (Exception ex)
{
Log(ex.Message);
return;
}
}
}
else
{
Log("No updates");
}
Log("Operation complete");
UpdateComplete.Set();
}
void SendGetConfig(string ip, ConcurrentQueue<UdpMessage> C)
{
byte[] msg = new byte[11];
msg[0] = 1;
msg[7] = 5;
msg[8] = 0x42;
UdpDispatcher.Send(new UdpMessage(ip, 20367, msg, 11), C);
}
void GetCnaInfo(CNA cna)
{
int WaitTicks;
ConcurrentQueue<UdpMessage> CnaRxQ = new ConcurrentQueue<UdpMessage>();
int tries = 0;
while (++tries < 4)
{
WaitTicks = 0;
SendGetConfig(cna.ip, CnaRxQ);
while (++WaitTicks < 100)
{
if (CnaRxQ.TryDequeue(out UdpMessage msg))
{
ushort label = (ushort)((msg.data[7] << 8) + (ushort)msg.data[8]);
if (label == 0x0543)
{
if (msg.data[0] > 1)
{
string firmware = string.Format("{0}.{1}.{2}", msg.data[1], msg.data[2], msg.data[3]);
cna.updated = true;
if (cna.firmware == firmware)
{
Log(string.Format("Skipping {0}: firmware is current", cna.ip));
}
else
{
Log("Updating " + cna.ip);
QueryBuilder qb = new QueryBuilder("update cna_firmware set firmware_rev = ");
qb.AddString(firmware, QBOptions.NONE);
qb.Query += " where ip_address = ";
qb.AddString(cna.ip, QBOptions.NONE);
updates.Add(qb.Query);
}
return;
}
else
{
Log(string.Format("Skipping {0}: unexpected data received", cna.ip));
return;
}
}
else
{
Log(string.Format("Skipping {0}: unexpected data received", cna.ip));
return;
}
}
Thread.Sleep(100);
}
}
Log("Unable to fetch config data from " + cna.ip);
cna.error = true;
}
void GetIpList()
{
SqlConnection DB;
string query;
using (DB = new SqlConnection(Globals.ConnectionString))
{
try
{
DB.Open();
}
catch (Exception)
{
UpdateComplete.Set();
return;
}
query = "select ip_address, n_cktid, firmware_rev from cna_firmware order by ip_address";
try
{
using (SqlCommand sql = new SqlCommand(query, DB))
{
using (SqlDataReader dr = sql.ExecuteReader())
{
if (dr.HasRows)
{
while (dr.Read())
{
int ckt = Sql.Read<int>(dr, "n_cktid");
string ip = Sql.Read<string>(dr, "ip_address");
string fw = Sql.Read<string>(dr, "firmware_rev");
if (cnas.ContainsKey(ip)) continue;
cnas.Add(ip, new CNA(ip, fw, ckt));
}
}
}
}
}
catch (Exception ex)
{
Log(ex.Message);
}
}
}
}
}
Thanks,
|
|
|
|
|
Quote: He built it with threading and the program crashes
Stop right there and describe the crash, any exceptions you get, and any related messages you may dig out of the Application Event Log.
Beyond this one statement, everything else you said is mere speculation without any understanding of the underlying problem. That's a recipe for a lot of wasted time.
Research the problem, not the proposed "solution".
|
|
|
|
|
The crash that occurs occasionally. Is Exception Unhandled System.IndexOutOfRangeException: 'Index was outside of the bounds of the array.'. This occursis an at the GetCnaInfo(CNA cna) of the code I previously posted, where it reads updates.Add(qb.Query);.
I have stepped thru the code, set break points where the query starts, and I am not finding what the issues is that is causing the IndexOutOfRangeException.
Sometimes this will run all the way thru the routine and not error. Clear the field in the database and run the routine again and then I get this error.
Thanks,
|
|
|
|
|
Well, this is definitely not a thread pool or "number of threads" issue. This is more of a data management and control problem.
That means, it seems like one thread is removing items from an array and another thread is asking for an item at an index that doesn't exist anymore.
The calls to Thread.Sleep lead me to believe that the code is poorly written in the first place. The Sleeps were put in there as a naive way of getting around a problem that the original coder didn't understand. Thread.Sleep should never be used in the code you've posted.
You said the problem shows up at updates.Add(qb.Query). I have no idea what that QueryBuilder class is and that seems like what would be throwing the exception.
The reference to updates.Add is just a List<string> and that will not throw the exception. The array bounds are managed internally by the List class and never fail like your exception describes.
modified 6-Jul-18 11:06am.
|
|
|
|
|
Thank you Dave, that helps me on where to look.
Much appreciated.
|
|
|
|
|
To add to what Dave said, while there are limits to how many threads can be created and that varies according to your OS, 32 /64 bit selection, and the required thread stack size, but for a 64 bit system, it's possible to generate in excess of 50,000 threads from a single process.
There is an interesting explanation here: Pushing the Limits of Windows: Processes and Threads – Mark's Blog[^]
But the more important question would be "why the elephant would you even try to generate that many threads, give that you probably only have 4 or 8 cores to run them on?".
And in your case, why do you think it's hitting a thread limit? What have you done that leads you to that conclusion? Why has it "suddenly" started happening? Or did it ever work? Is his code finished and tested?
I'd start with those questions before I even thought about changing the code in any way...
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
public Invoice(InvoicePresentation pmodel)
{
this.InitializeComponent();
this._pmodel = pmodel;
base.InitialFocus = this.txtBarcode;
this.pauseForm = new PauseEntry();
this.pauseForm.StartPosition = FormStartPosition.CenterParent;
this._itemActionsView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._customerActionsView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._invoiceActionsView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._taskActionsView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._toolsActionsView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._returnActionsView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._taskPad1X10View = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._invoiceActionsForCCView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._invoiceActionsForDSView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._taskActionsForDSView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
this._taskActionsForCCView = Unity.Instance.Resolve(new ResolverOverride[]
{
new ParameterOverride("invoiceUI", this)
});
Unity Class
public class Unity
{
private static readonly IUnityContainer _instance = new UnityContainer();
public static IUnityContainer Instance { get{ return Unity._instance;
}
}
but Error Show
Quote: Error 77 'Microsoft.Practices.Unity.IUnityContainer' does not contain a definition for 'Resolve' and the best extension method overload 'Microsoft.Practices.Unity.UnityContainerExtensions.Resolve(Microsoft.Practices.Unity.IUnityContainer, System.Type, params Microsoft.Practices.Unity.ResolverOverride[])' has some invalid arguments
|
|
|
|
|
Member 11056180 wrote: UnityContainerExtensions.Resolve(this IUnityContainer, Type, params ResolverOverride[]) Member 11056180 wrote:
Unity.Instance.Resolve(new ResolverOverride[] { ... });
The first parameter to the extension method (other than the "this" parameter it extends) needs to be a Type .
You are passing an array of ResolverOverride objects.
Change your code to pass the required Type as the first parameter.
Unity.Instance.Resolve(typeof(TheRequiredType), new ResolverOverride[] { ... });
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i dont know how to code it
|
|
|
|
|
Which bit don't you know how to code? Have you got code to read the file in? What format is it in? Are the dates in the file in a meaningful format? Are you reading the data into a meaningful structure in some way?
This space for rent
|
|
|
|
|
Hi,
I am developing applications on C # WinForm
Using MaskedTextBox and Mask Structure (999) 000 00 00 I use
Only when the user clicks with the mouse, it focuses on the pressed point
This Data Entry Is Incorrect and Incomplete
MaskedTextBox with User Mouse and Tab How I Can Focus on the Top of the Beginning
I look forward to helping you in this regard
Best Regards...
|
|
|
|
|
I'm sorry, but that makes no sense at all to me.
Perhaps an example would help?
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
But a Right Situation and a Problem
When I'm Clicked and Moved to the Mouse How Can I Trigger the Home Key?
SendKeys.Send("{HOME}");
It does not seem like it
|
|
|
|
|
ibrahimayhans wrote: Only when the user clicks with the mouse, it focuses on the pressed point
This Data Entry Is Incorrect and Incomplete Your perception is incorrect. The described behaviour is default in Windows, and Windows apps should adhere to the standard.
ibrahimayhans wrote: MaskedTextBox with User Mouse and Tab How I Can Focus on the Top of the Beginning If you tab into it, you are at the beginning.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm Into Content With TAB
Only User Uses Mouse Sometimes
There are such Problems when you click
|
|
|
|
|
ibrahimayhans wrote: Only User Uses Mouse Sometimes
There are such Problems when you click It is not a problem, it is how it is supposed to work. When activating a control with the mouse, the cursor does not go to the start but where you select. All controls work like that. Making it work differently means unexpected behaviour.
Also, someone doing data-entry does not move to the next control using the mouse, it would make for very inefficient data-entry.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I think you are asking how to move the textbox caret to position 0 when the empty textbox is clicked.
The first part is to get the empty state of the maskedtextbox before any data has been entered. At that point the Text property value is not String.Empty but a representation of the mask. This 'empty' text can be obtained by capturing the Text when the MaskChanged event fires. For your example it is
"( ) "
The second part is picking a suitable place to move the caret. When an unfocussed textbox is clicked the sequence of Enter, GotFocus and Click events occur. You'll find that attempting to set the caret position in either the Enter or GotFocus events will fail and changes must be made in the Click event handler.
Combining that information gives some prototype code
private String emptyText;
private void MaskedTextBox_MaskChanged(object sender, EventArgs e) {
MaskedTextBox mtbx = (MaskedTextBox)sender;
emptyText = mtbx.Text;
}
private void MaskedTextBox_Click(object sender, EventArgs e) {
MaskedTextBox mtbx = (MaskedTextBox)sender;
String currentText = mtbx.Text;
if (currentText == emptyText) {
mtbx.Select(0, 0);
}
}
EDIT : Correct operation of this code requires that the MaskChanged event handler is attached before the Mask is set.
Alan.
|
|
|
|
|
Hello everyone and specially Jose Menendez Póo, author of the Quote: A Professional Calendar/Agenda View That You Will Use article.
I must say that I'm overwhelmed by its complexity and beauty.
I wonder if any of you, who are familiar with this project, have any kind of written stuff or any kind of notes explaining the project in some details.
Also, the project uses a utility class of the name Quote: System.Windows.Forms.Calendar.dll and I wonder again if the class is ever published, or if any of you have access to it in the non compiled version, So I can study it.
I hope to get an answer here.
Thank you all,
Mark
|
|
|
|
|
The place for asking about things from an article is the discussion at the foot of the article itself. Here, you're hoping the author might stumble across your message. There, he will be notified of your inquiry.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|