|
hi
i want to backup from my database i used following code but it do not work properly
and it rises an exception
(my database name is 'Alarms' )
Backup backup = new Backup();
backup.Action = BackupActionType.Database;
backup.BackupSetName = "Archive_NeaxExpander";
backup.Database = "Alarms";
backup.PercentCompleteNotification = 10;
BackupDeviceItem device = new BackupDeviceItem(path, DeviceType.File);
ServerConnection connection = new ServerConnection(new SqlConnection(ConnectionString));
Server server = new Server(connection);
Database DB = server.Databases["Alarms"];
backup.Initialize = true;
backup.Checksum = true;
backup.ContinueAfterError = true;
backup.Devices.Add(device);
backup.Incremental = false;
backup.FormatMedia = false;
backup.SqlBackup(server);
i recive following exception
Microsoft.SqlServer.Management.Smo.FailedOperationException was unhandled by user code HelpLink="http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.1399.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Backup+Server&LinkId=20476"
Message="Backup failed for Server 'MRTSOFT-F5CFDAC'. "
Source="Microsoft.SqlServer.Smo"
Operation="Backup"
i used my current connectionstring as an addmin
to add , insert , select ,... and it works properly
and i sore that i have backup premission with this connectionstring
i used the following code to resive servers list
DataTable dtServers = SmoApplication.EnumAvailableSqlServers(false);
//or
DataTable dtServers = SmoApplication.EnumAvailableSqlServers(true);
but it`s dtServers.rows.count is zero and perhaps it means no server is available
so what can i do
i really confused by SQL
|
|
|
|
|
realize the truth
----------------------------------
Be excellent to each other
|
|
|
|
|
I need to implement vfp function which uses * and ? wildcards:
static bool Like( cExpression1, cExpression2)
cExpression1
Specifies the character expression that Like( ) compares with cExpression2.
cExpression1 can contain the wildcards such as * and ?. The question mark
(?) matches any single character in cExpression2 and the asterisk (*)
matches any number of characters. You can mix any number of wildcards in any
combination in cExpression1.
cExpression2
Specifies the character expression LIKE( ) compares with cExpression1.
returns true on wildcards match.
How to implement this ?
Andrus
|
|
|
|
|
You should look up Regex (Regular Expressions), it should do everything you need (and oh so much more)
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
You should look at using regular expressions. Do a search on this site for Expresso, it is a really cool tool for building regular expressions.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
|
Is there a way to use the .NET cryptography library to encrypt binary files as opposed to plain text files? I've been having a few issues with the way that encrypted bytes are decrypted back to their original state.
What I do to initialize my algorithm for decryption is approximately the following:
UnicodeEncoding byteConverter = new UnicodeEncoding();
RijndaelManaged algorithm = new RijndaelManaged();
algorithm.IV = byteConverter->GetBytes();
algorithm.Key = byteConverter->GetBytes();
return alg;
In order to encrypt, first, I call that stub of algorithm initialization code. Then I do approximately the following with a Byte[] data that I want to encrypt:
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, algorithm.CreateEncryptor(), CryptoStreamMode.Write);
for (int i = 0; i < numBytes; i++)
{
cs.WriteByte(data[i]);
}
cs.FlushFinalBlock();
byte encoded[] = ms.ToArray();
cs.Close();
ms.Close();
string output = Convert.ToBase64String(encoded);
In order to decrypt, first, I call that stub of algorithm initialization code. Then I do approximately the following with a string input that I want to decrypt:
byte[] encoded = Convert.FromBase64String(input);
MemoryStream ms = new MemoryStream(encoded);
CryptoStream cs = new CryptoStream(ms, algorithm.CreateDecryptor(), CryptoStreamMode.Read);
byte decoded[] = new byte[encoded.Length];
for (int i = 0; i < decoded.Length; i++)
{
int readByte = cs.ReadByte();
if (readByte != -1)
{
decoded[i] = (byte)readByte;
}
}
cs.Close();
ms.Close();
The problem is that if I call Encrypt , then Decrypt , encryption leaves me with a nice base64 string, which decrypt easily converts back to a byte array. But when I read the CryptoStream and get check all the values of int readByte everytime I read a byte, as soon as I come to the null-terminated character (0 '' ), everything else that I read after that is the same garbage symbol (-51 'Í' ). More precisely, the code that I'm writing here is the C# equivalent of my Managed C++ code (however, the problem does not lie in the unmanaged part or the unmanaged/managed conversion). So, to rephrase what I mean, say that I'm checking all the values of readByte for i = 0 to the length of the decoded byte array (which hasn't yet been filled), if ReadByte happens to return me 66, 77, 54, 44, 23, 0, respectively, everything else after that is -51. If I'm decrypting binary data, I will run into this issue. If I'm decrypting text data, then I won't, since in a text string, 0 is the null-terminated character that only occurs at the very end of the string (and I've got all my bytes at that point anyway).
Any suggestions? Thanks, and I apologize for the long post.
|
|
|
|
|
Skip the base 64 string part. Since you are using a binary file you should be using a FileStream or some other stream. I have never had any trouble encrypting streams.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Well, base64 is easily encoded in a string, or a MemoryStream (which is what I'm using). What I'm essentially doing afterwards when I write to a file is actually saving the base64 encoded string directly to the file like I save text. Thanks for the FileStream suggestion... maybe that's also a plausible implementation.
Also, I've toyed around with the idea of doing multiple base64 conversions, so converting a binary file to base64 first, then encrypting, then encoding to base64 again. After every base64 transform step, I'm able to again fit the entire "data" of the file into an ANSI string.
|
|
|
|
|
I just figured out the issue, and it had nothing to do with the CryptoStream. I was simply deceived and made the wrong assumptions. In the end, it was because I never opened the file in binary mode, so it was being parsed as a string.
|
|
|
|
|
You have a binary file, and the crypto stream only encrypts or decrypts binary data. There is no reason at all to turn the data into a string.
As I always say:
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
This is a little library I use. I pulled it together from various sources and stake no claim to it. It will encrypt binary and strings using public/private key encryption and standard passphrase encryption. Hope it's of some help.
Crptography.zip[^]
|
|
|
|
|
Hi,
Is there a way to produce a partial method with CodeDom?
Ex. partial void MyMethod() { ... }
It looks like the MemberAttributes doesn't have "Partial" in it
CodeMemberMethod codeMemberMethod = new CodeMemberMethod();
codeMemberMethod.Attributes = MemberAttributes.Public...but no MemberAttributes.Partial?
My problem is that I'm generating some code to implement partial method.
I have this class (created "by hand"):
public partial class MyClass
{
partial void MyMethod();
partial void MyMethodB();
}
Then with CodeDom, I want to generate the implementation of those partial method. Something like:
public partial class MyClass
{
partial void MyMethod()
{
}
partial void MyMethodB()
{
}
}
That's why I need the "Partial" in System.CodeDom.MemberAttributes.
May be I'm all wrong...it's something else the MemberAttributes that I should use to do this?
Thank
|
|
|
|
|
Create an abstract class and then use CodeDom to return an instance. You don't even need an abstract class as you can use an interface as well.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Sorry, but the CodeDOM classes don't support partial methods.
|
|
|
|
|
|
I created 3000 labels and added them into my form (I really didn't need these labels, I was just testing).
My C# code:
int x, y;
Label[] lab = new Label[3000];
for (int i = 0; i < 3000; i++)
{
lab[i] = new Label();
x = i / 100;
y = i % 100;
lab[i].Tag = string.Format("{0},{1}", x.ToString(), y.ToString());
lab[i].AutoSize = false;
lab[i].Top = (x - 1) * 10;
lab[i].Left = (y - 1) * 10;
lab[i].Height = 10;
lab[i].Width = 10;
this.Controls.Add(lab[i]);
}
My VB6.0 code:
Dim i%
Dim x$
Dim y$
For i% = 2 To 3000
Load lblPage(t%)
x$ = i% \ 100 + 1
y$ = i% Mod 100
lblPage(i%).Tag = x$ + "," + y$
lblPage(i%).Top = (i% \ 100) * lblPage(1).Height
lblPage(i%).Left = (i% Mod 100 - 1) * lblPage(1).Width
lblPage(i%).Visible = True
Next i%
And my problem is speed!
C#: about 5seconds
VB6: less than a second!!!
Why?
Besides I have to insert approximately 100MB .Net Framework package in my installation package while I really don't need all of .Net Framework features, in this case I have to tell my users: "Please be patient! We'll continue after a while! "
Is there anyway to solve these problems? If not I think I'll not use C# anymore!
|
|
|
|
|
Pedram Behroozi wrote: And my problem is speed!
Then use C++...
Stupidity is an International Association - Enrique Jardiel Poncela
Die deutsche Sprache sollte sanft und ehrfurchtsvoll zu den toten Sprachen abgelegt werden, denn nur die Toten haben die Zeit, diese Sprache zu lernen. - Mark Twain
|
|
|
|
|
You're creating 3000 labels and adding them to the screen. Of course that's gonna be slow; that's a horrible abuse of the UI system. (As many VB6 apps are!)
Your VB6 code is different than your C# code. The C# code creates 3000 labels and adds them to the screen. Your VB6 code assumes your labels are already created and merely sets their visible status.
Tell us what you're trying to do. We'll tell you how to get good performance.
Pedram Behroozi wrote: Besides I have to insert approximately 100MB .Net Framework
Use the .NET 3.5 SP1 client profile. It's just over 20MB.
Another thing to consider is that all Windows Vista machines come pre-installed with .NET 3.
modified on Friday, September 26, 2008 1:50 PM
|
|
|
|
|
Judah Himango wrote: Tell us what you're trying to do. We'll tell you how to get good performance.
As I said before, I was just testing. I encountered the speed problem before in many cases. Like reading records from a file using StreamReader or even BinaryReader while the same VB6 application executed that in a moment!
Judah Himango wrote: Use the .NET 3.5 SP1 client profile. It's just over 20MB.
Even 20MB is a huge size! Imagine I want to write a simple Phonebook, My application needs 20.01MB free space!
|
|
|
|
|
The problem is that you're writing VB code in C#. Write C# code meant to run on the .NET framework, .NET performance will blow VB6 out of the water.
Pedram Behroozi wrote: Even 20MB is a huge size!
No it's not. Standard hard drive these days are 500 GB. That means the .NET framwork is 1/25,000th the size of the hard drive.
If you don't want to use the whole .NET framework, use Silverlight. It's a 4 MB subset of the .NET framework.
modified on Friday, September 26, 2008 2:30 PM
|
|
|
|
|
Pedram Behroozi wrote: Even 20MB is a huge size!
Do you realize this is the year 2008 and 20mb is a splash in the bucket these days? Maybe in 1991 with an 80MB hard drive it would be a whole different story
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Few issues to point out:
- you are comparing two totally different languages and environments. What is optimal in VB6 may not be optimal in C# and vice versa
- your code is not equal. You have several major differences in your code
- predefined labels in VB6
- in C# you access properties which you do not use in VB6
- you modify control collection in C# and so on
- the output is different in .Net (MSIL) than in VB6 (native EXE)
- you may have not optimized code and you may have DEBUG & TRACE options on in C# etc.
However, in real world situation, in most cases .Net beats VB6 in all areas, since you have more possibilities to achieve the same goal but in a more efficient way.
I'm all the time referring to .Net instead of C#, because C# is just one of the languages you can use in .Net. If you make the same test using VB.NET, you'll have similar results. However C# gives you the opportunity to use more efficient coding than VB.NET so it would be more reasonable choice for the language.
If performance still is an issue with MSIL code, you can always use ngen at target machine.
Mika
The need to optimize rises from a bad design
|
|
|
|
|
Mika Wendelius wrote: If performance still is an issue with MSIL code,
Definitely yes, I wrote a program that should read 5000 records from a file. I tried C# to add these records to a DataGridView control (I even tried simple ListBox) and to be honest with you C# done it in 20 seconds. But my uncle wrote this application via VB6 and japed me!
I actually preferred C#, but I need high speed and low size.
Mika Wendelius wrote: you can always use ngen at target machine.
What is "ngen at target machine"?
|
|
|
|
|
For the first comment: You must play by the rules of C#. If done properly, it beats VB6, that's for sure, but the code is not the same or even transferrable.
For the second comment: Native Image Generator (Ngen.exe)[^]
Mika
P.s. Have faith and work your way with C# and you'll show your uncle
The need to optimize rises from a bad design
|
|
|
|