|
Hello to all,
When I'm running my application from the debug folder, I'm able to save changes to the database, but when I load the Crystal report to display that data, it still displays the old data, i.e., the data before the changes.
Does it have anything to do with the database Build Action property and Copy property or it has something to do with the report source path?
Thanks a lot,
JC.
|
|
|
|
|
Hello,
I have been trying to use this triple des encryption code to encrypt then decrypt passwords. Basically I write the password out to a file, read it in then decrypt it. Using this code works fine while the app is running. Once I exit the app and read the encrypted password in the DecryptPassword method throws the error CryptographicException Message="Bad Data.\r\n" on the FlushFinalBlock() method. I found some of this code here and the other peice from Microsoft. Both work exactly the same way, while the app is running they can encrypt/decrypt strings but if I exit the app and start again, read the data from my file they both get the same error. I have attached the class with all the code and the exception. If anyone can help it would be greatly appreciated.
code:
================
using System;
using System.Collections.Generic;
using System.Text;
namespace notify
{
class crypto
{
private static System.Security.Cryptography.SymmetricAlgorithm TripleDES = new System.Security.Cryptography.TripleDESCryptoServiceProvider();
public void InitializeKeys()
{
//TripleDES.Key = System.Convert.FromBase64String("b4r5OegLw8Mz8wlMJ8isuSGSev1IgzMA");
//TripleDES.IV = System.Convert.FromBase64String("6qu72vdn0Fs=");
}
public string EncryptPassword(string ClearTextPassword)
{
TripleDES.Key = System.Convert.FromBase64String("b4r5OegLw8Mz8wlMJ8isuSGSev1IgzMA");
TripleDES.IV = System.Convert.FromBase64String("6qu72vdn0Fs=");
///////////////// Code Project Code /////////////////////////////////////////////////////////////////////////////////////
string encrypted;
byte[] Code = ASCIIEncoding.ASCII.GetBytes(ClearTextPassword);
encrypted = Convert.ToBase64String(TripleDES.CreateEncryptor().TransformFinalBlock(Code, 0, Code.Length));
return encrypted;
/////////////////// Microsoft Code ////////////////////////////////////////////////////////////////////////////////////////
//System.Security.Cryptography.ICryptoTransform ct;
//System.IO.MemoryStream ms;
//System.Security.Cryptography.CryptoStream cs;
//byte[] byt;
//ct = TripleDES.CreateEncryptor(TripleDES.Key, TripleDES.IV);
//byt = System.Text.Encoding.UTF8.GetBytes(ClearTextPassword);
//ms = new System.IO.MemoryStream();
//cs = new System.Security.Cryptography.CryptoStream(ms, ct, System.Security.Cryptography.CryptoStreamMode.Write);
//cs.Write(byt, 0, byt.Length);
//cs.FlushFinalBlock();
//cs.Close();
//return System.Convert.ToBase64String(ms.ToArray());
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
public string DecryptPassword(string EncryptedPassword)
{
TripleDES.Key = System.Convert.FromBase64String("b4r5OegLw8Mz8wlMJ8isuSGSev1IgzMA");
TripleDES.IV = System.Convert.FromBase64String("6qu72vdn0Fs=");
///////////////// Code Project Code /////////////////////////////////////////////////////////////////////////////////////
string decrypted;
byte[] Code = Convert.FromBase64String(EncryptedPassword);
decrypted = ASCIIEncoding.ASCII.GetString(TripleDES.CreateDecryptor() .TransformFinalBlock(Code, 0, Code.Length));
return decrypted;
/////////////////// Microsoft Code ////////////////////////////////////////////////////////////////////////////////////////
//System.Security.Cryptography.ICryptoTransform ct;
//System.IO.MemoryStream ms;
//System.Security.Cryptography.CryptoStream cs;
//byte[] byt;
//ct = TripleDES.CreateDecryptor(TripleDES.Key, TripleDES.IV);
//byt = System.Convert.FromBase64String(EncryptedPassword);
//ms = new System.IO.MemoryStream();
//cs = new System.Security.Cryptography.CryptoStream(ms, ct, System.Security.Cryptography.CryptoStreamMode.Write);
//cs.Write(byt, 0, byt.Length);
//cs.FlushFinalBlock();
//cs.Close();
//return System.Text.Encoding.UTF8.GetString(ms.ToArray());
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
}
====================================
exception:
====================================
System.Security.Cryptography.CryptographicException was unhandled
Message="Bad Data.\r\n"
Source="mscorlib"
StackTrace:
at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.Utils._DecryptData(SafeKeyHandle hKey, Byte[] data, Int32 ib, Int32 cb, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode PaddingMode, Boolean fDone)
at System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
at notify.crypto.DecryptPassword(String EncryptedPassword) in C:\Data\Visual Studio 2005\Projects\notify\notify\crypto.cs:line 53
at notify.frmMain.frmMain_Load(Object sender, EventArgs e) in C:\Data\Visual Studio 2005\Projects\notify\notify\frmMain.cs:line 232
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at notify.Program.Main() in C:\Data\Visual Studio 2005\Projects\notify\notify\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Darryl
|
|
|
|
|
It looks like I made a silly mistake. Using UTF8 encoding does't work well. I simply changed it to use System.Text.ASCIIEncoding.ASCII.GetString();
|
|
|
|
|
hai ,iam trying to get the image from video camera and save it in the database directly, for that i used a code which gives out of memory error. iam giving the code below, pls correct me or give me the code for that.
string strFnn=this.imageFileName;
this.pictureBox.Image=Image.FromFile(strFnn);
...........
|
|
|
|
|
Is there anyway to fire an event when the mouse moves over the notifyicon? and another when it moves out?
JGA
|
|
|
|
|
I would like to increase the height of the rows in the datagrid whenever data is binded to the grid.
So, How do I get the notification whenever the datagrid is binded to a Datasource.
The DataSourceChanged event occurs only when there is a change in the DataSources value. When I bind the same datasource to the datagrid, the DataSourceChanged event won't fire.
How can this be handled.
Thanks in advance.
Subrahmanyam K
|
|
|
|
|
hi Subrahmanyam K!
try to shadow the DataSource property, like this:
public new object DataSource
{
get {return base.DataSource;}
set
{
base.DataSource = value;
}
}
hope that helps!
microsoc
|
|
|
|
|
Hi
a simple question cause due to a C++ to C# migration.
Is there a User thread available (not a worker thread) like the CWinThread in VC++
codito ergo sum
|
|
|
|
|
Is System.Threading.Thread what you are looking for?
|
|
|
|
|
I dont thinks so,
It seems to me that this is a worker thread object, a function is called in a different
thread but when the function is done the thread will end. In my case the threads need to
be up the whole time. And I need to send system messages from/to the different threads in my application.
I don't find functions or objects to do this. Am I missing something??
codito ergo sum
|
|
|
|
|
When the function is done, the thread will always end. If you want the thread to keep running, you just have to keep the function from ending. Put a look in it that listens for messages. If there is no messages, let it sleep for a while.
---
b { font-weight: normal; }
|
|
|
|
|
You must be talking about User-interface threads which have a message pump. I think you will have to play with Application.Run and Windows Forms.
|
|
|
|
|
Something like that, but the threads have no GUI.
How can I achive a message pump ??
codito ergo sum
|
|
|
|
|
hi
i need to convert the poiners in c++ to C#
how can i do it ?
for example i have this code in c++
and the main problem is with the *Word
i need to use the same funtions (i have dll for the them)
but i have problems with the variables or parameters
void *StopMemory;
int ErrorCode;
int LanguageID = 1;
int CharCodeID = 1;
char *Word = "the";
ErrorCode = ExtrCreateStopMemory(&StopMemory);
ErrorCode = ExtrAddStopWord(StopMemory,LanguageID,CharCodeID,(void *) Word);
hope somebody will help me
thanks
eyalso
|
|
|
|
|
To use pointers in C# you have to put them within a class defined as "unsafe" through the unsafe keyword.
|
|
|
|
|
the unsafe keyword can also be used inside a function
unsafe
{
//code with unsafe pointers
}
be sure to use the -unsafe compile option when building!
|
|
|
|
|
Marshal, Marshal, Marshal
You can use Managed C++ or C++/CLI to wrap the native code or use P/Invoke from C#.
|
|
|
|
|
Hi, to make my code readable I'd like to write a reference to a variable that is embedded in a structure. For instance,
double Xmax = Xset.Xmax.X
double Xmin = Xset.Xmin.X
where Xset.X{}.X is a double itself. The code I just write above returns a copy. In c++ I'd just assign a pointer to .X and use Xmax or Xmin thruout the code. Changes to Xmax / Xmin in that case change Xset.Xmax.X etc.
Is there a way in C# to set Xmax / Xmin as a reference to the .X values?
Thx.
|
|
|
|
|
You're asking for reference semantics on value types. You can do this between methods using the ref keyword:
int i = 5;
MyFunc(ref i);
void MyFunc(ref int someInteger)
{
someInteger = 10;
}
But in order to get reference semantics throughout any piece of code, not just between methods, you have 2 options.
1. Use unsafe code. Just as it is in C, you can use pointers the same as you would in C. Only caveat is that you need to compile with the /unsafe switch, and also mark code that uses pointers with the unsafe keyword. For example, the following is perfectly legal C# code:
unsafe
{
double someVal = 200;
double *c = &someVal;
}
2. Use a wrapper class to wrap your value, thus automatically giving it reference semantics:
public class Wrapper<T>
where T : struct
{
public T Value;
}
Wrapper<double> Xman = Xset.Xmax.X;
Wrapper<double> Xmin = Xset.Xmin.X/
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
No, you can't reference a value type.
You can get a pointer to the values, but that would cause two nasty things:
1. You would have to use the fixed keyword to fix the object in memory. The garbage collector doesn't really like if you fix objects for a long time, as it wants to move stuff around sometimes.
2. You would have to use the unsafe keyword whenever you would access the values, or make the entire code unsafe (which is an extremely bad idea).
If it's only the simplicity in the code you are after, just declare properties to access the values:
private double Xmax { get { return Xset.Xmax.X; } set { Xset.Xmax.X = value; } }<br />
private double Xmin { get { return Xset.Xmin.X; } set { Xset.Xmin.X = value; } }
---
b { font-weight: normal; }
|
|
|
|
|
To both of you,
Thanks for your clear responses. I particularly like making Xmax and Xmin local properties... didn't think of that.
I think I'm good to go now.
|
|
|
|
|
How do I send Arguments to an executeable?
Any help is appreciated.
<marquee bgcolor="#000000" loop="-1" scrollamount="6" width="100%">
Wacky waving inflateable arm flailing tube man!
|
|
|
|
|
It depends, do you want to send an argument during debug, or for a 'released' exe?
If you are debugging you want to go to your projects properties (not the solutions) and under the 'debug' tab there's a textbox for 'Command Line Arguments'.
For use with an actual exe, create a shortcut to the exe, open the shortcuts properties. There will be a textbox titled target (in winxp). put the path that's in the in quotes ("path\to\exe") and then you can put any arguments behind that.
|
|
|
|
|
|
|