|
I have a windows app connecting to a webservice. In some situation(s) (haven't narrowed it down enough), I get the following exception:
The underlying connection was closed: The connection was closed unexpectedly.
Please help.......
Regards
Pankaj Joshi
|
|
|
|
|
hi all
I have a .net web application. I need to copy a file present on the web server machine to a remote machine on the network. how is it possible? i tried using CopyTo(); methode. but not working. somebody told me that copy file is not possible in web application. but i think download file is possible only for website. then how is it done?
please help me.
|
|
|
|
|
P_Elza wrote: i think download file is possible only for website. then how is it done?
Use WebClient class and WebClient.DownLoadFile() method
|
|
|
|
|
The MSDN example at:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_cscomp/html/ba881e38-2abf-4a5f-b9e6-28d26a5bd235.htm
Shows the following code and says it will throw an "Error Message: Use of possibly unassigned field 'field'; A field in a structure was used without first being initialized."
public struct error<br />
{<br />
public int i;<br />
}<br />
<br />
public class MyClass<br />
{<br />
public static void Main()<br />
{<br />
error e;<br />
System.Console.WriteLine( e.i );
}<br />
}
But it's my understanding that the compiler generated constructor for a struct automatically intializes the fields to zero, false, or null.
Since the struct in the example has no explicit constructor, why isn't i being initialized to zero?
|
|
|
|
|
Hi,
it is not related to your struct, the same is true for all value types, example:
public class MyClass {
public static void Main() {
int e;
System.Console.WriteLine( e );
}
}
i.e. local variables need explicit initialization.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That confuses me some. I want my struct to have usable default values. But you are saying that any code which uses my struct does not have access to values that I set in it's constructor (or that the compiler sets for me)?
|
|
|
|
|
Hi,
JoeRip wrote: That confuses me some. I want my struct to have usable default values.
To test struct initialization you had to use a class member "error", not a local variable.
The compiler insists local variables are initialized before they are used.
A class member "error" will have all its members initialized to zero/null/Nothing...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
"
this default constructor is only invoked if the struct is instantiated with new.
"
|
|
|
|
|
AH! That's my error, thanks. For a minute there I thought I was fundamentally misunderstanding what structs were for.
|
|
|
|
|
I just found out myself. I spent most of the day Sunday wrestling with a struct .
It should be possible to define a default constructor for struct s dagnabit!
|
|
|
|
|
Hi experts,
(I hope I didn't post my question in the wrong category of the forum)
I am using in C#, Asp.Net, SQL Server for my project.
I have a situation whereby I need to update a primary key.
In my table, I have these columns:
[U]proj_id[/U], emp_name, emp_email
I have the following method
public static void updatePID(String newpid,String oldpid)
{
SqlConnection conn = new SqlConnection(connString);
SqlCommand comm = new SqlCommand("Update table_name set proj_id = newpid where proj_id = oldpid");
conn.Open();
comm.Connection = conn;
comm.Parameters.AddWithValue("@projectid", newpid);
comm.Parameters.AddWithValue("@projectid", oldpid);
comm.ExecuteNonQuery();
conn.Close();
}
I have a problem with the following two statements.
comm.Parameters.AddWithValue("@projectid", newpid);
comm.Parameters.AddWithValue("@projectid", oldpid);
My connection with the database and the variables "newpid" and "oldpid" values are correct.
May I know if there is any other methods to update a primary using the old primary key? Thank You in Advance.
serene
|
|
|
|
|
Ummm... how about:
...
SqlCommand comm = new SqlCommand("Update table_name set proj_id = @newpid where proj_id = @oldpid");
...
comm.Parameters.AddWithValue("@newpid", newpid);
comm.Parameters.AddWithValue("@oldpid", oldpid);
...
|
|
|
|
|
Thanks but it's still working. There isn't any update in the database although there is no compliation or runtime error.
Er.... I guess there is something wrong with my logic? Please help..
protected void Page_Load(object sender, EventArgs e)
{
// It did display the first(old) project id into the textbox.
String projectID = (String)Session["projId"];
txtProjId.Text = projectID;
}
protected void btnConfirm_Click(object sender, EventArgs e)
{
//get project id
String newpid = txtProjId.Text;
String oldpid = (String)Session["projId"];
ProjectDAO.updatePID(newpid, oldpid);
}
I wanted to display the project Id that the user has first entered. It was saved in the database.
Then the system allows them to change the project Id at another page.
Erm.. and the only reason I can think of it that "String newpid = txtProjId.Text; " values is the old value instead.
Any idea how to make this work?
Thanks. Sorry for the trouble.
serene
|
|
|
|
|
Try this:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
String projectID = (String)Session["projId"];
txtProjId.Text = projectID;
}
}
Hope it helps
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
A big thanks to both of you.
It's working already!
Thanks again
;)
serene
|
|
|
|
|
Pfft:
txtProjId.Text = (String)Session["projId"];
Stupid needless local variable.
|
|
|
|
|
|
Hi, I want to be able to send keystroke to anther app that is based directx. I am using SendInput for the major part of the keys, but there are serveral keys that dont work with this fuction. (most of the ones that dont, calls a action of some sort). I just woundering if my next step is to start looking into directx api hooking or is there another way that i can send the keystroke over the sendinput that might work. Also i have tried the Sendkeys function but all it gets is the same key action on all the keys (whish is the ESC key).
thank you very much
Danzar
|
|
|
|
|
How to work TTS in arabic
write sentence arabic and speak whin i need that
|
|
|
|
|
Your inquiry goes way beyond the scope of a forum post. Try google searches
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi there,
I am making a stock take application for MC50 Pocket PC which runs on Windows 2003 Mobile OS. I have written some code to update stock after every qty entered for a stock item. This function updates the database (.sdf file on PDA) with the entered qty. I have found out that if battery runs out or if the PDA is hard rebooted WHILE doing stock take, my stock take is not saved at all. Seems like the data is rolled back or is not committed when PDA is rebooted while doing stock take. Please help me to save data every time i enter qty for a stock item even if the PDA is hard rebooted. Thanks very much. - KARAN
My code is:
"
#region Update Stock Take by Ref number
///
/// updates stock take table with new qty by ref number
///
/// <param name="ref_number" />
/// <param name="qty" />
/// <returns>
internal string UpdateStockTakeByRefNumber(string ref_number,decimal qty, string column)
{
string sql = "UPDATE Stock_Take SET " + column +" = ? , Updated_By_PDA = 1 WHERE Ref_Number = ?";
try
{
SqlCeHelper.ExecuteScalar(cnStockLink,sql, new SqlCeParameter(column,qty), new SqlCeParameter("Ref_Number",ref_number));
}
catch (SqlCeException e)
{
MessageBox.Show(e.Message.ToString());
}
return "Y";
}
#endregion
"
|
|
|
|
|
I just had an idea and I'd like your opinion.
When you use "for" cycles you have to use lock if more than one thread is executing that part because they may interfere with each other when incrementing the cycle-variable. You have to use lock():
lock(lockObject) {
for(int i = 0; i<x; i++)
{="" do="" work="" }="" }
my="" solution
first="" i="" use="" thread.name="" to="" name="" my="" threads="" with="" an="" int="" in="" a="" cycle,="" like="" this:
for(int="">threadArray.Length; i++)
{ threadArray[i].Name = i.toString(); }
I have to create an array of integers, with the same number of elements as the threads.
int[] intArray = new int[numOfThreads];
Finally my for looks like this:
for(; intArray[Convert.ToInt32(Thread.CurrentThread.Name)]) < x; Interlocked.Increment(ref intArray[Convert.ToInt32(Thread.CurrentThread.Name)]))
{ //Do work }
This way multiple threads can access a cycle instead of waiting until the running thread exits the lock. What do you think?
|
|
|
|
|
szolDat wrote: When you use "for" cycles you have to use lock if more than one thread is executing that part because they may interfere with each other when incrementing the cycle-variable.
Not at all. The variable is allocated on the stack, so it's local to each thread.
I don't know where you got that idea, but either you misread something, or you have read something written by a very confused person.
szolDat wrote: This way multiple threads can access a cycle instead of waiting until the running thread exits the lock. What do you think?
I think that you have totally misunderstood the problems with thread safety.
You have "solved" a problem that doesn't exist, and created a problem as the access to the array no longer is syncronised.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
"You have "solved" a problem that doesn't exist"
Please explain why the following situation isn't possible (I'm somewhat clear about the heap and the stack):
Thread1 enters the cycle, increments i by 1.
The control is passed to Thread2 and it enters the cycle too, incrementing i by 1. i now equals 2.
Thread1 gets control again and tries to access an array's element (or perform any action) using the cycle variable. There you have it, a race condition where the value of i depends on the order of the threads' access to the cycle.
Another thing is, every calculation will give bad results which depends on the number of executions and there are variables involved which are mutually modifiable by the threads. In this situation you have to use a lock, or you can use the method I proposed.
Thank you for your attention.
|
|
|
|
|
Have you tried it the other way? Or just believed some rubbish that was floating around the Internet?
Because your i is defined within the method, each invocation will have its own i , not one shared one. Thread safety comes into effect with fields -- items that are defined in a class or struct.
Here, I whipped up a little (!) demo:
namespace Template
{
public partial class Template
{
private int[] values ;
private int classi ;
public Template
(
int HowMany
)
{
this.values = new int [ HowMany ] ;
for ( int i = 0 ; i < HowMany ; i++ )
{
this.values [ i ] = i ;
}
return ;
}
public void
PrintLocal
(
object Format
)
{
for ( int locali = 0 ; locali < this.values.Length ; locali++ )
{
System.Console.Write
(
(string) Format
,
this.values [ locali ]
) ;
}
return ;
}
public void
PrintClass
(
object Format
)
{
for ( this.classi = 0 ; this.classi < this.values.Length ; this.classi++ )
{
System.Console.Write
(
(string) Format
,
this.values [ this.classi ]
) ;
}
return ;
}
public void
PrintClassWithLock
(
object Format
)
{
lock ( this.values )
{
for ( this.classi = 0 ; this.classi < this.values.Length ; this.classi++ )
{
System.Console.Write
(
(string) Format
,
this.values [ this.classi ]
) ;
}
}
return ;
}
[System.STAThreadAttribute]
public static int
Main
(
string[] args
)
{
int result = 0 ;
Template t = new Template ( 100 ) ;
try
{
System.Threading.Thread a = new System.Threading.Thread ( t.PrintLocal ) ;
System.Threading.Thread b = new System.Threading.Thread ( t.PrintLocal ) ;
a.Start ( " A({0:00})" ) ;
b.Start ( " B({0:00})" ) ;
while ( a.IsAlive && b.IsAlive )
{
System.Threading.Thread.Sleep ( 100 ) ;
}
System.Threading.Thread c = new System.Threading.Thread ( t.PrintClass ) ;
System.Threading.Thread d = new System.Threading.Thread ( t.PrintClass ) ;
System.Console.WriteLine() ;
System.Console.WriteLine() ;
c.Start ( " C({0:00})" ) ;
d.Start ( " D({0:00})" ) ;
while ( c.IsAlive && d.IsAlive )
{
System.Threading.Thread.Sleep ( 100 ) ;
}
System.Threading.Thread e = new System.Threading.Thread ( t.PrintClassWithLock ) ;
System.Threading.Thread f = new System.Threading.Thread ( t.PrintClassWithLock ) ;
System.Console.WriteLine() ;
System.Console.WriteLine() ;
e.Start ( " E({0:00})" ) ;
f.Start ( " F({0:00})" ) ;
while ( e.IsAlive && f.IsAlive )
{
System.Threading.Thread.Sleep ( 100 ) ;
}
}
catch ( System.Exception err )
{
System.Console.Write ( err.Message ) ;
}
return ( result ) ;
}
}
}
|
|
|
|