|
I knew that... but wat i wanted is how to close all connections that are opened @ that time
|
|
|
|
|
Do you know how to use google?
I tried with - "kill connections sql server" and all of the top 10 results had the answer.
|
|
|
|
|
BUT, to kill connections (not your own) you need sa rights, not something which most accounts should have.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Yap, this is true, but if you are building an administrative module you should grant this kind of rights to the admin of the application.
|
|
|
|
|
Shorgov wrote: you should grant this kind of rights to the admin of the application.
Matter of opinion. It allows far to much damage to be done - do you really want to give a user the right to drop tables etc?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Only to the appropriate user
In general I am agreed with you, but user not allays means dumb person. User of this admin module can be a developer(responsible for the maintenance of the system ) or a trained consultant who knows what he is doing.
|
|
|
|
|
Dear friends..
i have small problem ..
this is my code
private DateTime convertByteToDatetime(byte[] Data)
{
try
{
DateTime now = DateTime.Now;
byte[] year = new byte[2];
year[0] = Data[0];
year[1] = Data[1];
int nYear = convertByteToInt(year);
DateTime dt = new DateTime(nYear, (int)Data[2], (int)Data[3], (int)Data[4], (int)Data[5], (int)Data[6]);
return dt;
}
catch
{
return (null);
}
}
in Catch block i can't return null because Datetime is value type
i do not want to return any date if there is an error....
What shall i do..
Any idea.? suggestion?
By
joe
|
|
|
|
|
You have two options. You could return default(DateTime); or change the return type to Nullable<DateTime>
[edit] You could also rethrow the exception. I find this a tad ugly, but whatever works for you
modified on Thursday, December 3, 2009 12:05 PM
|
|
|
|
|
Thank Your friend ...
for Your replay ..
0x3c0 wrote: Nullable<datetime>
what this line will return? sorry i do not know.
how to use this Nullable<datetime>?
syntax please?
thank U
|
|
|
|
|
You replace private DateTime convertByteToDatetime(byte[] Data) with private Nullable<DateTime> convertByteToDatetime(byte[] Data) . Then you can either return new Nullables, or just keep your code and rely on the implicit operators. If you do that, you don't need to do anything apart from checking HasValue in your calling code. If that's true, then retrieve value.
Example:
Nullable<DateTime> nullableDate = convertByteToDatetime(new byte[] {0, 0, 0});
if(nullableDate.HasValue)
else
However, please be aware that this will call your code to fail silently. I would personally raise an event detailing the exception before I return null so that I know precisely what went wrong without having to sprinkle try-catch blocks everywhere.
|
|
|
|
|
Thank You frined .....
i shall try that .
|
|
|
|
|
=>Joe<= wrote: if there is an error...
... throw an Exception.
|
|
|
|
|
thanks for your replay...
PIEBALDconsult wrote: ... throw an Exception.
i do not want stop the process ... in other words i have skip to othere work ..
thank U
|
|
|
|
|
That's up to the calling routine to decide.
|
|
|
|
|
=>Joe<= wrote: Any idea.? suggestion?
AFAIK there are four popular ways, you've had most of them already:
1.
set aside a special value, could be Default<DateTime> or any other value you don't need as a real value. For DateTime, there is also DateTime.MaxValue
2.
nullable types, written either as Nullable<DateTime> or DateTime? (with question mark)
I don't like them much as they take more memory, and cause some trouble when parts of your environment don't know how to handle them (e.g. files, databases, ...).
3.
Use an Exception. That often is the most elegant approach, assuming the "no value" situation really is exceptional.
[ADDED, AS SUGGESTED BY PIEBALD]
4.
Return a boolean and have the value in an out parameter. Like with TryParse.
[/ADDED]
modified on Thursday, December 3, 2009 2:59 PM
|
|
|
|
|
thank you friend for your replay...and the suggestion ...
|
|
|
|
|
Now it's worth a ten.
|
|
|
|
|
can you explique more please?? do you like to return DataTime null in the catch??
why??
|
|
|
|
|
Luc should probably also have said:
4. Return a boolean and have the value in an out parameter. Like with TryParse.
|
|
|
|
|
fixed
|
|
|
|
|
Hi there
I am having problems developing a C# application that sorts the data in an
SQL database by a particular column and then outputs it to a csv file on my
hard drive.
I want to do something like this:
SqlCommand sqlComm = new SqlCommand("SELECT * FROM TableA ORDER BY ColumnB
INTO OUTFILE ‘C:\output_file.csv’", myConnection);
Is this the right way to go about it?
Thanks in advance
|
|
|
|
|
totally_stumped wrote: SELECT * FROM TableA ORDER BY ColumnB
INTO OUTFILE ‘C:\output_file.csv’
Doesn't looks like it will execute on SQL server. AFAIK, you will need to use BCP to export data to csv file. Or, you can get the data from database in your code and then write that to CSV.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
You should know that the sql command is executed on the computer where the MS SQL server is installed. This means that "C:\output_file.csv" is server's C drive. You may have no access to it! The second problem is the query itself. I think that this query is only available for MySQL user.
A better approach will be to get the data from the server into a DataSet (on client side) and write a simple method to convert the data to scv file.
I am quite sure that an article explaining how to do this exists in CP's articles.
|
|
|
|
|
Maybe you should ask in the database forum.
But seriously; you'll need to write some code. Use a DataReader to read the data, then write each row to the file. It's not a big deal.
|
|
|
|
|
I am kind of digging into this threading business and having some trouble. I created the threads (one for prefilling a bunch of information from a SQL database, and another one for inserting files into the database if the user chooses to do so). So the first on happens on load and the other one could happen at any time by either clicking the Attach button, or by dragging and dropping a file from the desktop to the listview.
Problem is when I spawn the thread and the user closes the form before the file is uploaded (the form is a child form and is not the parent main form), it gives an error about the control cannot be invoked when the handle is not created. OK, I understand that it has disposed of the forms controls and thats why it has done this... but how do I make sure these threads are stopped before disposing of all the components on the form?
Here is the method I used to pass the information about the file. So I call this method on the main thread and this methods sets the global variables (so the new thread can access them and have the information to insert into the database), show the progressbar, and then spawn the thread. As you can see the thread is not a declared globally so the dispose method cannot access it directly correct?
private void SaveFile(string fileName, string safeFileName, bool fileMR)
{
this.fileName = fileName;
this.safeFileName = safeFileName;
this.fileMR = fileMR;
if (fileMR)
picProgressFilesMR.Visible = true;
else
picProgressFiles.Visible = true;
Thread fileThread = new Thread(new ThreadStart(saveFiles));
fileThread.IsBackground = true;
fileThread.Start();
}
|
|
|
|