|
how can write protection class for applications created in c# which work with a validation key or serial number etc ?
is there any way to do it crack proofed?
also i'd like my program be available for a specific "trial period" and be locked after this period. application shoul not be "unlocked" after Reinstalling.
thanks in advance.
knowledge is power (%)
|
|
|
|
|
persian_king wrote: is there any way to do it crack proofed
You come with that and Bill Gates will sing at your birthday party.
There are plenty of third party products that offer these types of features. You can always write your own, but of course it will only be as good as your code and testing process.
|
|
|
|
|
Hello,
I think this will helpfull to u.
regards,
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
Hello everyone,
This may seem like an odd question but here goes.
I'm using the PropertyGrid for a project of mine -- works great and I've used the EnumDescConverter and PropertySorter TypeConverters that I found on CodeProject.
Basically I have an (older) application (.NET 1.1) that I have moved to .NET 2.0. In the older application, I had a class with a Layers property that contained a collection of Layers. I used the ExpandableObjectConverter to let the PropertyGrid show a + sign beside the layers as well as a list of the layers. This was great. Basically it was something like
public class Config
{
...
private LayerCollection m_Layers = new LayerCollection();
[TypeConverter(typeof(ExpandableObjectConverter))]
public LayerCollection Layers
{
get { return m_Layers; }
}
...
}
LayerCollection implemented CollectionBase, as well as ICustomTypeDescriptor to show "Layer #" beside each entry. This worked great.
Now, however, I'm restructured things so that it looks something like this:
public class Config
{
...
private List<Layer> m_Layers = new List<Layer>();
public List<Layer> Layers
{
get { return m_Layers; }
}
...
}
If I apply the ExpandableObjectConverter to the Layers properties, it just shows the Count property of the List. Hmmm. Not what I wanted. I know I'm missing something here -- just not sure what.
I used the generic List because it was easy -- but now I'm thinking that I may have to go back and have a LayerCollection class again so that it can implement the ICustomTypeConverter. Maybe make that generic so I can reuse it, but still.
Any ideas? Has anyone else run into a similar fiasco?
Thanks!
-Matt
|
|
|
|
|
Nevermind
I created a class called ExpandableList<T> that inherits from List<T> AND implements ICustomTypeDescriptor.
This is a pretty useful technique, I'll post it as an article soon.
-Matt
Bart: Look at me, I'm a grad student. I'm 30 years old and I made $600 last year.
Marge: Bart, don't make fun of grad students. They've just made a terrible life choice.
-- modified at 22:27 Wednesday 12th July, 2006
|
|
|
|
|
I first tried this code that passes a couple of parameters (part number, part type number) to a stored procedure. I can get this to run fine, insert the data into the table, no problem.
However, I want the stored procedure to return a field that is an auto-increment field called ID.
The stored procedure is syntactically correct, so I'm inclined to think it's something with the C# code.
The error I'm getting is: Parameter1 is not a parameter for procedure UpdatePart_Step_1_Test3
This is the c# code (note that I have so additional parameters that I declare but am not yet passing):
private void btnAdd_Click(object sender, System.EventArgs e)<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
strPartTypeID = ddPartType.SelectedValue;<br />
strDwgNumber = txtDwgNumber.Text;<br />
strDwgRevision = txtDwgRevision.Text;<br />
strDwgLocation = txtDwgLocation.Text; <br />
SqlParameter param1 = new SqlParameter("@PartNumber", strPartNumberInputReference); <br />
param1.Direction = ParameterDirection.Input;<br />
SqlParameter param5 = new SqlParameter("@PartTypeValue", strPartTypeID);<br />
SqlParameter param6 = new SqlParameter(@ID, SqlDbType.Int);<br />
param6.Direction = ParameterDirection.Output;<br />
IDOutput = SqlHelper.ExecuteNonQuery (this.connectionString, CommandType.StoredProcedure, "dbo.UpdatePart_Step_1_Test3", param1, param5, param6);<br />
test3 = param6.Value;<br />
<br />
}
Here is the stored proc:
CREATE PROCEDURE [dbo].[UpdatePart_Step_1_Test3]<br />
@PartNumber varchar (15),<br />
@PartTypeValue varchar (60),<br />
@ID int OUTPUT<br />
<br />
AS<br />
<br />
if NOT EXISTS (Select * from PartsDB.dbo.Parts where PartNumber = @PartNumber)<br />
BEGIN<br />
<br />
insert into PartsDB.dbo.Parts<br />
(PartNumber, PartTypeID)<br />
<br />
VALUES<br />
(<br />
@PartNumber,<br />
@PartTypeValue<br />
)<br />
<br />
END<br />
SET @ID = @@IDENTITY<br />
<br />
return 0<br />
GO
Again, if I just send in param1 and param 5 (and change the stored proc so it's not expecting a third parameter) it works fine!
Any ideas what is causing the error? I'm not finding any documentation.
|
|
|
|
|
leckey wrote: SqlHelper.ExecuteNonQuery
This is obviously a helper class, what does the code look like ?
Your code knows far too much about your data layer, why have a helper method and pass it SQL Parameters ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I think the helper is from the Microsoft Application Block for DAL
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
|
I'm not quite sure what you mean by the second part...
I also tried with a dataset (even though the sp is just an insert) and got the same error. If I don't try to return anything, it's fine.
The code in the helper class goes through quite a bit, so I'll try to paste it as the compiler goes through it.
Step 1:
public static int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)<br />
{<br />
if( connectionString == null || connectionString.Length == 0 ) throw new ArgumentNullException( "connectionString" );<br />
<br />
using (SqlConnection connection = new SqlConnection(connectionString))<br />
{<br />
connection.Open();<br />
<br />
return ExecuteNonQuery(connection, commandType, commandText, commandParameters);<br />
}<br />
}
Step 2:
public static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)<br />
{ <br />
if( connection == null ) throw new ArgumentNullException( "connection" );<br />
<br />
SqlCommand cmd = new SqlCommand();<br />
bool mustCloseConnection = false;<br />
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection ); RUNS THIS FINE <br />
int retval = cmd.ExecuteNonQuery(); GETS STUCK ON THIS<br />
<br />
cmd.Parameters.Clear();<br />
if( mustCloseConnection )<br />
connection.Close();<br />
return retval;<br />
}
If there is a quick and painless other way to do this I'm all ears...or eyes really. I just want to get done with this!
|
|
|
|
|
leckey wrote: I'm not quite sure what you mean by the second part...
Your presentation layer shouldn't do more than call the middle tier with the data that needs storing. The middle tier should pass the data to a database layer, and inside THAT you should write code that knows what stored proc is being called.
The big question is, why are you using this Microsoft thingy ? What is it giving you ? I've done code that calls a stored proc and gets the out param heaps of times, but I have no idea on how best to use this Microsoft layer that you've got in place, or why you'd use a layer when your overall approach is not n-tiered at all.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I haven't programmed in about 3 years and a programming friend recommended it to me.
Could you give me an example? The more specific the better...I'm not very bright.
|
|
|
|
|
An example of the call, or of proper n-tiered development ?
SqlCommand cmd = new SqlCommand("InsertTrack", Connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@artistName", (artist == null) ? "" : artist);
cmd.Parameters.Add("@trackName", (track == null) ? "" : track);
cmd.Parameters.Add("@albumName", (album == null) ? "" : album);
cmd.Parameters.Add("@filePath", filePath);
cmd.Parameters.Add("@isVideo", isVideo ? 1 : 0);
cmd.Parameters.Add("@thumbPath", (thumbPath == null) ? "" : thumbPath);
cmd.Parameters.Add("@trackID", -1);
cmd.Parameters["@trackID"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
return (int) cmd.Parameters["@trackID"].Value;
That's a call out of the data layer of a video jukebox I wrote. It represents a complete static function in a class that has the Connection as a lazy initialised static member property.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: cmd.Parameters.Add("@trackID", -1);
Why -1 versus SqDbType.Int?
I'll be trying your version of code in a minute...be wary..I'll probably have more questions.
|
|
|
|
|
That code is a little over complex, it's passing in some values based on booleans. However, the add method takes a name and a value, not a value type, from the look of it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Okay, question time!
I have my connection in my web.config file and have this declared in my code behind:
private string connectionString = ConfigurationSettings.AppSettings["connectionString"].ToString();
So I changed my code to:
private object btnAdd_Click(object sender, System.EventArgs e)<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
strPartTypeID = ddPartType.SelectedValue;<br />
SqlCommand cmd = new SqlCommand ("UpdatePart_Step_1_Test3", connectionString);<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.Parameters.Add ("@PartNumber", strPartNumberInputReference);<br />
cmd.Parameters.Add ("@PartTypeValue", strPartTypeID);<br />
cmd.Parameters.Add("@ID",SqlDbType.Int);<br />
cmd.Parameters["@ID"].Direction = ParameterDirection.Output;<br />
cmd.ExecuteNonQuery();<br />
return(int) cmd.Parameters["@ID"].Value;<br />
}
Problem 1: I bolded "connectionString"--the compiler is unhappy and not sure how to resolve this. Geting "cannot convert string..." so I assume I need to change the declaration...but what to?
|
|
|
|
|
It's actually an instance of a connection, which itself is built from the string.
SQLConnection is the class, I think.
// return(int) cmd.Parameters["@ID"].Value;
The return statement will work here, it will box the int and return it as an object. Why is this event handler trying to return an object, where was it called from ? An event handler returns void.
I doubt you want to return a boxed int tho, do you ? My method returned int and was inside a data layer, called from my business layer.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I'm leaving in 10 min, so if you get them through in time, I'll be happy to help, otherwise it'll be tomorrow morning.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
leckey wrote: SqlParameter param6 = new SqlParameter(@ID, SqlDbType.Int);
Was this just a copy/paste error? I'm pretty sure @ID needs to be in quotation marks.
Also, you should use SCOPE_IDENTITY()[^] instead of @@IDENTITY to get the ID of the row you just inserted. It's not strictly necessary, but it's a good habit to get into. More details in the remarks section on the MSDN site.
Jon Sagara
When I grow up, I'm changing my name to Joe Kickass!
My Site | My Blog | My Articles
-- modified at 17:17 Wednesday 12th July, 2006
|
|
|
|
|
Jon, you are the winner!!! That was my problem. I need to get this done but will probably later take Christian's advice.
As Steve the Pirate says in Dodgeball...
"Gargh!"
|
|
|
|
|
Yeah, I missed that, although when he said, from what you said, I thought it was blowing up elsewhere.
Yes, you definately need to read up on seperation of the presentation tier, although your code will work, it's a design issue.
http://www.15seconds.com/issue/011023.htm[^]
looks like an OK place to start with a quick overview.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Many thanks again for your help!
|
|
|
|
|
I am not sure if this can be done. I am writing a console application to ftp files. This will be called by a scheduling program. Is there a way to return a value if the transfer fails?
Lyman Ring
|
|
|
|
|
See if this works
static int Main(string[] args)
{
return 3;
}
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
Thanks, My next question would be how to check this value
|
|
|
|
|