|
I did .. but not sure how to exactly word it in search. that's why this post.
thanks anyway..
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
Hi everybody, I've made a POS System and @ the exit I want to make an automatic Backup which copies the database to some place ... but it says the database is used ... & I tried to find where it is unclosed (it is thousand of lines of code).... and I cant get it ... so can anybody help me ... how write some line of code which will close any opened connection to that database? ..
Thank you
|
|
|
|
|
Perhaps Management Studio has the database open? If so, you have to close Management Studio; I don't think you can close another application's connection, at least it shouldn't be your standard operating method.
modified on Thursday, December 3, 2009 2:19 PM
|
|
|
|
|
I didnt get what you said... Can you elaborate it to me
|
|
|
|
|
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
|
|
|
|