|
You seem to be missing a lot of code here. I would expect to see code to actually write to the database. Merely setting parameters doesn't do anything. I also don't see any use of your UInfo class in there. Could you post the missing bits please? Without them, we can't really offer more help.
|
|
|
|
|
Hi Pete,
Good to "see" you again. The sql connection code goes
using (SqlConnection UserInfo = new SqlConnection("User id = xxx; password = yyy; server=aaa\\bbb;" +
"database=mydb;connection timeout=30"))
{
SqlCommand in = new SqlCommand("INSERT INTO dbo.ccc(Tstamp, SysID, LogOnUser, DefUser," + "AltDefUser, UAuthType, UAuth, UGuest, USIDNo, USIDPlain, UToken)" +
"VALUES (@Tstamp, @SysID, @LogOnUser, @DefUser,"
+ "@AltDefUser, @UAuthType, @UAuth, @UGuest, @USIDNo, @USIDPlain, @UToken)", UserInfo);
I can assure you the the SQL part of it works 100% because a) if I use static values (e.g. AuthType = "a") then that values writes to the db and b) if I do
[DllImport("advapi32", SetLastError = true), SuppressUnmanagedCodeSecurityAttribute]
static extern int OpenProcessToken(System.IntPtr ProcessHandle, int DesiredAccess, ref IntPtr TokenHandle);
[DllImport("kernel32", SetLastError = true), SuppressUnmanagedCodeSecurityAttribute]
static extern bool CloseHandle(IntPtr handle);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public extern static bool DuplicateToken(IntPtr ExistingTokenHandle, int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);
public const int TOKEN_DUPLICATE = 2;
public const int TOKEN_QUERY = 0X00000008;
public const int TOKEN_IMPERSONATE = 0X00000004;
public void OnTimedEvent(object source, ElapsedEventArgs e)
{
IntPtr hToken = IntPtr.Zero;
IntPtr dupeTokenHandle = IntPtr.Zero;
Process proc = Process.GetProcessById(2568);
if (OpenProcessToken(proc.Handle,TOKEN_QUERY|TOKEN_IMPERSONATE|TOKEN_DUPLICATE, ref hToken) != 0)
{
WindowsIdentity newId = new WindowsIdentity(hToken);
try
{
const int SecurityImpersonation = 2;
dupeTokenHandle = DupeToken(hToken, SecurityImpersonation);
if(IntPtr.Zero == dupeTokenHandle)
{
string s = String.Format("Dup failed {0}, privilege not held",
Marshal.GetLastWin32Error());
throw new Exception(s);
}
WindowsImpersonationContext impersonatedUser =
newId.Impersonate();
IntPtr accountToken = WindowsIdentity.GetCurrent().Token;
RegistryKey RegKeyDU = Registry.LocalMachine;
in.Parameters.Add("@UAuthType", SqlDbType.NVarChar, 40).Value = AuthType;
UserInfo.Open();
inu.ExecuteNonQuery();
UserInfo.Close();
}
}
finally
{
CloseHandle(hToken);
}
}
else
{
string s = String.Format("OpenProcess Failed {0}, privilege not
held", Marshal.GetLastWin32Error());
throw new Exception(s);
}
}
Then the data writes properly, i.e. If I incorporate the method into the exising class everything works as it should...
|
|
|
|
|
Sorry, got to go to bed . Been up 18 hrs now -eyes tired, brain tired. Look forward to talking more tomorrow.
Thanks for you input so far...
|
|
|
|
|
When you want to return multiple values, create a data class, with either properties or fields in it. I tend to just make them fields because properties don't gain you anything in this case (the purpose of the class is to expose all its data anyway). In this case you want to put all these things
string Token = accountToken.ToString();
string WinID =
WindowsIdentity.GetCurrent().Name;
string IsAuthd =
newId.IsAuthenticated.ToString();
string AuthType = newId.AuthenticationType;
string IsGuest = newId.IsGuest.ToString();
string SIDNo = newId.Owner.ToString();
string SIDPlain =
newId.Owner.TranslatTAccount)).ToString());
... in a data class (possibly UInfo itself) as public fields.
|
|
|
|
|
BobJanova wrote: I tend to just make them fields because properties don't gain you anything in
this case
Personally, I never expose fields, only properties. In many cases there is no gain, but it provides the flexibility to perform validation or make read only etc in the future. There is very little work required to create the properties and is much more maintainable IMHO.
|
|
|
|
|
I don't see why you need to make them properties if you might upgrade them in the future. If you need to make them readonly, for instance, it's a simple matter to convert them at that point.
|
|
|
|
|
The reason I do it is to make a clear distinction between data classes and 'active' classes. Validation is something which is generally part of logic and shouldn't be done by a pure data class. If I have a class that exposes fields, it's the only thing (apart from a constructor or some non-state-changing lookup functions that are trivial combinations of the fields) that it will expose.
Maintainability for a field is no worse than an auto-property, as they're source code equivalent in usage.
|
|
|
|
|
If I create a stock ActivityDesigner project, don't change anything, I can open the xaml file and see the designer.
If I create a stock ActiveLibrary project and double click on the Activity1.xaml file, I get: Index was out of range. ???
Same problem if I create a WCF workflow service and try double clicking on the xamlx file. Am I missing some component or something?
Never worked with WF before, just messing around with it.
|
|
|
|
|
Wouldn't this be better asked in the WCF and WF[^] forum?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
How would I go about getting a list of namespaces and/or assemblies referenced in a solution?
Everything makes sense in someone's mind
|
|
|
|
|
You'd normally try to do this through a Visual Studio extension. Get a reference to the DTE and that gives you access to all sorts of handy functionality. Alternatively, you could try the Object Browser if you just want an easy way to view this info.
|
|
|
|
|
This might work:
typeof(SomeClassName).Assembly.GetReferencedAssemblies
|
|
|
|
|
Guys,
Am trying to access the data from SQL SERVER 2008 via C#. I am getting an Exception. I am sure that I have problem with the query. please check this and reply...
The Code is:
private SqlDataReader GetInContainers(DateTime tFromDate,DateTime tToDate)
{
SqlConnection mycon = new SqlConnection(@"server=XYZ ; database = ABC; Trusted_Connection=yes");
mycon.Open();
string sql="Select CntNo, iso_code, InDateTime from gatein_containers where (InDateTime between #" + tFromDate.ToString("MM/dd/yyyy HH:mm:ss") + "# and #" + tToDate.ToString("MM/dd/yyyy HH:mm:ss") + "#) " +
" and (SHIPPING_LINE_CODE='1' or SHIPPING_LINE_CODE='MSL') order by InDateTime";
MessageBox.Show("Going to Execute");
SqlCommand myCommand = new SqlCommand(sql, mycon);
myReader = myCommand.ExecuteReader();
mycon.Close();
mycon.Dispose();
MessageBox.Show("Executed");
return myReader;
}
I am able to get the result when I use simple querty like:
sql="select * from daily;
|
|
|
|
|
A few things to note - you should use parameters for your queries, rather than using the text directly - you leave yourself wide open to SQL injection attacks here. When you say you get an exception, you should really tell us what the exception is, we can't read your mind. It's generally not a good idea to format your dates to anything other than the ISO standard, internally it will be stored as ISO - so you'll get a problem when you attempt to do this. AFAIK, SQL Server doesn't use # to delimit dates in queries, that's an Access format.
|
|
|
|
|
The # is the date delimiter in MS Access and SQL Server does not recognize that. Use the single quote to delimit dates. The default date format is YYYY/MM/DD. You can specify date in this format directly or use the convert function if you wish to specify date in other formats.
|
|
|
|
|
hi everyone, i've a form with a datagridview containing Name, and email address field. I've added another button column to this grid and on the click event of this button I'd like to concantenate the mailto: process and the email address field. Something like this:
if (this.dgvPresenters.Columns[e.ColumnIndex] is DataGridViewButtonColumn)
{
Process.Start("mailto + '"(this.dgvPresenters[e.ColumnIndex,e.RowIndex].Value.ToString())"'+"); }
the email field in the DB is saved as name@company.com - hope this makes sense.
Thank you
|
|
|
|
|
Hi,
To start writing mail, the correct instruction is:
Process.Start("mailto:name@company.com");
then you must change you code as:
Process.Start("mailto:" + this.dgvPresenters[e.ColumnIndex,e.RowIndex].Value.ToString());
|
|
|
|
|
thanks this helped me out
|
|
|
|
|
|
thank you for the link, I've bookmarked it for future reference
|
|
|
|
|
IS it possible to filter an excel sheet from # form. The excel sheet will be opend from Excel application or from Excel viewer. For example customer want to know the lowest price of the itemsize starting with '23565'. The excel sheet contain many items with that item size of diffrent manufacturer starting with 23565 . When the user type in textbox of the form , the excel sheet should be filtered by the value giving on the textbox.
Pls have any idea that would be very appreciate.
Pol
|
|
|
|
|
Excel already has that capability. What is it you are looking for?
Failure is not an option; it's the default selection.
|
|
|
|
|
You can use Excel Automation to do that. This[^] post will help you get started.
|
|
|
|
|
Hi there,
I have some files in my website for being downloaded by signed in users.
But due to the bandwidth limitation I have to restrict users to download only a specefic size per day for example 100MB per day.
Now I'm looking for a way to measure the user's download size.
Any help please?
|
|
|
|
|
You should really have asked this in the ASP.NET forum. Anyway, assuming that you only allow logged in users to download files, on every download request you would get the size of the specified file and see if adding it to the days total would take the user over the limit.
I know this seems obvious, but bear with me: the wrinkle you have is in defining what counts as a day - is it based on the last 24 hours activity, or is it based on an arbitrary point such as midnight on the database server. The reason you need to know this is because this will affect your calculation as to the previous day. Now, I would suggest storing the current server time in the database against each download for the user as it will make your calculations easier.
Further wrinkles for you to think about. What happens if the user aborts a download and then restarts it? Does this count towards your size limit? How are you going to handle the switch over when the clocks go forwards and backwards by an hour?
|
|
|
|