|
Iterate the items in the ComboBox controls (I am assuming they both have the same number of items), create a ListViewItem, set its text and sub-item text and add it to the ListView.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
We have an asp.net web application running in both .net 1.1 and 4.0. This application has a web.config file in the root folder where the authorization module is defined as
<authorization>
<allow users="*"/>
</authorization>
It has another web application in the sub directory where the web.config authorization module is as below
<authorization>
<allow roles="some valid role"/>
<deny users="*"/>
</authorization>
These configuration settings work fine in .net 1.1 but after migration to .net 4.0, the application is causing problems in providing appropriate access.
Is there any difference in reading the authorization module tags(<allow>,<deny>) of web.config of an application in .net 4.0 and 1.1 ?
|
|
|
|
|
They are using different authorizations schemes - the root authorization is user based only - the other requires a RoleProvider as well. Check you have an appropriate RoleProvider configured, and that the described role is enabled.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
The role access is checked for the logged in user, for whom the roles are defined in the database. There has been no change in the database neither in the role definition nor the access to the users. The problem is caused only after migration of the web application from 1.1 framework to 4.0 framework.
|
|
|
|
|
Perhaps you would like to ask this in the ASP.NET forum then. You are more likely to get an answer there.
|
|
|
|
|
hi i have a custom authentication used from
http://brianlegg.com/post/2011/05/09/Implementing-your-own-RoleProvider-and-MembershipProvider-in-MVC-3.aspx
i need to show a list of online users , can anyone help
|
|
|
|
|
A couple of thoughts;
As this is an ASP.NET issue, this should at least be asked in that forum rather than here.
Perhaps the author of the original code could help you. He's probably better placed to help you based on his code.
|
|
|
|
|
How I can dicipher a file with triples DES without Error, puisque j'ai essayer mais je récupér un texte en plus a la fin du fichier de sortie (la derniére ligne répéter), alors j'ai assurrer que c'est le dernier block et sachant que j'ai utilisé le formatage PKCS#7 et le mode CBC.
|
|
|
|
|
|
Think's JF2015 I'm succed to cipher ad decipher my data think you , my problem it was the file in input damaged , when i change the input file all was working good...
|
|
|
|
|
Greetings, you managed to insult both english and french languages in the same post...
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
Greetings Gurus,
Could you offer some advice/help please?
I am trying to read a SQL db for a specific value and add it in if not found. I have more-or-less got the procedure working but the DataReader recognises that the value exists then goes and adds it back in twice anyway.
try
{
string c = System.Environment.MachineName;
string Domain = System.Net.Dns.GetHostName();
ManagementObjectSearcher SerialNo = new
ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM
Win32_SystemEnclosure");
foreach (ManagementObject querySN in SerialNo.Get())
{
string SN = (querySN["SerialNumber"].ToString());
string SysIdent = c + SN + "@" + Domain;
SqlConnection conn1 = new SqlConnection("User id = a;
password = b; server=c; database=d;connection timeout=30");
SqlCommand selectname = new SqlCommand("SELECT FullName
FROM dbo.tablename", IdentSys);
IdentSys.Open();
SqlDataReader GetIdnt = selectname.ExecuteReader();
while (GetIdnt.Read())
{
string Names = Convert.ToString(GetIdnt["FullName"]);
{
if (Names != SysIdent)
{
SqlConnection conn2 = new SqlConnection("User id = a;
password = b; server=c; database=d;connection timeout=30");
SqlCommand newname = new SqlCommand("INSERT
INTO dbo.SysIdent(FullName) VALUES(@FullName)", InsertSys);
newname.Parameters.AddWithValue("@FullName",SysIdent);
InsertSys.Open();
newname.ExecuteNonQuery();
InsertSys.Close();
}
}
}
GetIdnt.Close();
}
}
catch (Exception f)
{
Console.WriteLine(f.ToString());
}
Could you advise what I am doing wrong please?
|
|
|
|
|
You should read all the Names in a List and if the List doesn't
contains the SysIdent value then add it.
A DataReader can't possibly add anything to the DB.
All the best,
Dan
|
|
|
|
|
Hi Dan,
I am aware that the datareader can't add the value, it was in there to illustrate what I'm trying to do
I'm not quite with you on your other statement though. Do you mean create a list<>Names = new list type of thing? If so, how?
|
|
|
|
|
Look at Lucs post below. About the logic, he explaind it I'm lazzy.
Create a List<string> add each item to the list in the while(reader.Read()) loop,
close the reader, check if the list contains what you wan't and if not add it.
Or do it direclty from SQL, eg check the number of rows where YourField equals what you want.
If the affected rows is 0 then it doesn't exist and you can add it. It should be faster.
All the best,
Dan
|
|
|
|
|
There is a flaw in the logic, your DB operations are equivalent to this:
foreach(record in records) {
if (record!=whatWeWant) insert(newRecord);
}
where it should be:
bool exists=false;
foreach(record in records) {
if(record==whatWeWant) exists=true;
}
if (!exists) insert(newRecord);
Now the existance can be checked without an explicit loop, try an SQL statement akin to this:
SELECT COUNT(1) FROM dbo.tablename WHERE FullName = @ValueWeSearch
which you should run through an ExecuteScalar() operation; the COUNT function makes it return one number, the number of matching records; when 0 insert, otherwise don't.
[EDIT] fixed typo [/EDIT]
modified 21-Nov-11 11:05am.
|
|
|
|
|
Luc & Dan,
Thank you very much for pointing out the trees
SqlCommand selectname = new SqlCommand("SELECT COUNT(*) FROM dbo.SysIdent WHERE FullName = @SysIdent", IdentSys);
selectname.Parameters.Add("@SysIdent", SqlDbType.NVarChar, 150);
selectname.Parameters["@SysIdent"].Value = SysIdent;
IdentSys.Open();
selectname.ExecuteNonQuery();
int Count = Convert.ToInt32(selectname.ExecuteScalar());
if (Count == 0)
{
}
|
|
|
|
|
Almost.
1. COUNT(1) is better than COUNT(*) as the latter may get confused by possible NULL fields (in any field of the record) whereas the former really counts matching rows.
2. Your ExecuteNonQuery() is totally redundant.
3. Your Convert.ToInt32() can be simplified to a simple cast using (int)
|
|
|
|
|
Luc Pattyn wrote: 3. Your Convert.ToInt32() can be simplified to a simple cast using
(int)
|
|
|
|
|
Thanks Luc & PIEBALDconsult, as always, your time spent educating us newbs is appreciated
|
|
|
|
|
There are a few changes I would make to your code if it was me developing this. First of all, I would wrap the SqlConnection and SqlCommand statements with using so that they are disposed of (which ensures that Close is called).
I would also change your insert statement to include the SELECT COUNT as part of the where clause. The reason that I would do this is because you are working in a multi-user database, so it's entirely possible that somebody else could be inserting the value between the time you did the SELECT COUNT and the INSERT . When you do checks like this, it's always important to remember the multi-user access nature of the database.
|
|
|
|
|
Hi Pete,
I'm busy fighting with some vba array code right now, but I'll test your suggestions tonight if that's ok.
|
|
|
|
|
That's fine. I should have also mentioned how you would do this - I'm assuming you are using SQL Server 2008 here, which allows you to do something called an UPSERT command. Basically, that's an INSERT and UPDATE command all rolled into one (although you can just use the INSERT part on its own).
The syntax you would use is
MERGE sometable
USING (select something FROM table) ON (value = @value)
WHEN NOT MATCHED THEN INSERT VALUES (...)
|
|
|
|
|
Hi Pete,
I'm not quite sure what you mean by
Pete O'Hanlon wrote: I would also change your insert statement to include the SELECT COUNT as part of the where clause
but was aware of the multi-user problem. My thoughts on overcoming that issue was to split the transactions into 3 parts, Look for name > if found use the associated ID, if not found > insert name > get Autonumber ID. My code (shabby and lumpy as it may be) currently looks like
try
{
string c = System.Environment.MachineName;
string Domain = System.Net.Dns.GetHostName();
ManagementObjectSearcher SerialNo = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM_
Win32_SystemEnclosure");
foreach (ManagementObject querySN in SerialNo.Get())
{
string SN = (querySN["SerialNumber"].ToString());
string SysIdent = c + SN + "@" + Domain;
using(SqlConnection IdentSys = new SqlConnection(some connection;connection timeout=30"));
using(SqlCommand selectname = new SqlCommand("SELECT COUNT(1) FROM dbo.SysIdent WHERE_
FullName = @SysIdent", IdentSys));
selectname.Parameters.Add("@SysIdent", SqlDbType.NVarChar, 150);
selectname.Parameters["@SysIdent"].Value = SysIdent;
IdentSys.Open();
int Count = (int)(selectname.ExecuteScalar());
if (Count == 0)
{
using(SqlConnection InsertSys = new SqlConnection(some other connection_;connection
timeout=30"));
using(SqlCommand newname = new SqlCommand("INSERT INTO dbo.SysIdent(FullName)_
VALUES(@FullName)", InsertSys);
newname.Parameters.AddWithValue("@FullName", SysIdent);
InsertSys.Open();
newname.ExecuteNonQuery();
InsertSys.Close();
}
IdentSys.Close();
using (SqlConnection selectID = new SqlConnection(another connection;connection timeout=30");
SqlCommand GetID = new SqlCommand("SELECT * FROM dbo.SysIdent WHERE FullName = @SysIdent", selectID);
GetID.Parameters.Add("@SysIdent", SqlDbType.NVarChar, 150);
GetID.Parameters["@SysIdent"].Value = SysIdent;
selectID.Open();
SqlDataReader GetmyID = GetID.ExecuteReader();
while (GetmyID.Read())
{
int myID = (int)(GetmyID["ID"]);
Console.WriteLine(myID);
Console.ReadLine();
int mySysId = myID;
if (!EventLog.SourceExists("mylog")) EventLog.CreateEventSource("mylog", "Application");
EventLog.WriteEntry("mylog", "ID" + mySysId + " allocated");
}
}
}
catch (Exception f)
{
if (!EventLog.SourceExists("mylog")) EventLog.CreateEventSource("mylog", "Application");
EventLog.WriteEntry("mylog", "Unable to allocate SysID" + f.ToString());
}
What are your thoughts?
On more-or-less the same issue, given that the end product will be a windows service, what would be the best way to ensure that the ID that is given on the first run remains permanently static. i.e, it will use the same ID when it runs timed_event_1 every 12 hours and the same ID for timed_event_2 which runs every 3 minutes?
|
|
|
|
|
Well, you have a few problems in there. First of all, you need to wrap the code that runs inside the using statements in a { } block so that it is all covered. Basically, using internally maps to a try/finally with the finally part triggering a Dispose , which is why it's good practice to use it on disposable items where possible. (This also explains why you can't use using on a non IDisposable item, as it actually does something like this in the finally part):
((IDisposable)myObject).Dispose(); Secondly, the idea I was talking about was to use the MERGE command as I explained in my followup post. As you haven't provided details on which DB you are using, I have assumed that you are using SQL Server 2008. Alternatively, you could use a command like this:
INSERT INTO dbo.SysIdent(FullName)
SELECT @FullName
WHERE NOT EXISTS (Select FullName FROM dbo.SysIdent WHERE FullName = @FullName) (Note that I've just quickly knocked this statement together in the message window - it might need some refinement). You could return the SCOPE_IDENTITY at this point following the insert to get the auto number that you just added in. Now, if I was being really defensive I would refine this idea to perform the select from SysIdent to see if I've already added the item (and return the id at this point), and if I hadn't added it, I would then perform the insert I demonstrate here. To make my job really easy, I'd put this all inside a stored procedure, so all my C# code would need to do is call the stored procedure to get this value back - don't make your data layer code more complicated than it needs to be.
CCodeNewbie wrote: On more-or-less the same issue, given that the end product will be a windows
service, what would be the best way to ensure that the ID that is given on the
first run remains permanently static. i.e, it will use the same ID when it runs
timed_event_1 every 12 hours and the same ID for timed_event_2 which runs every
3 minutes?
As you haven't said what these events are, I can't give a definitive answer, but I would probably have a property of the class that manages each one of these events which contains the number. It's that simple.
|
|
|
|