|
OK, the "simple" method is to cast it:
MyMethod((IEnumerable<int>)data);
which is, of course, really ugly. So, hide it in another overload:
public void MyMethod<T>(List<T> data)
{
MyMethod<T>((IEnumerable<T>)data);
}
Truth,
James
|
|
|
|
|
Whenever I can write the excel file from stored procedure but one field size is 12 digit.so It can return exponential number.How to return these actual number?
|
|
|
|
|
|
I think that you will find it is actually returning the number. Select the cell in the spreadsheet and look at the value in the formula bar. That should have the digits in it. The issue is that the default display for a large number is as an exponential format but the display is not what is actually stored.
Try, as a counter test, writing a (say) 15 digit number in a cell and then move to another cell then look at what the cell you wrote into has as its displayed value.
Update:
You can 'see' longer numbers in non-exponential format. Right click the cell(s), select Format Cells, Number tab / Category Number, set Decimal places to 0.
modified 2-Apr-20 9:40am.
|
|
|
|
|
"C# Oracle SYSDBA connection string not able to working on windows 10? But the same connection string is working on windows 7!"
|
|
|
|
|
It's probably not the connection string (though we have no idea what string you are using, how you are using it, or where your code is running).
More likely, it's a firewall / port blocking / security issue.
Talk to your Oracle DBA and see what he says first.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Not sure what you want us to do. We can't see anything that you have done.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I am using the below code to obtain a list of all local user accounts on the machine. But in addition to the "human" accounts, it returns all the other accounts, such as the SQLSERVER accounts and something called the WDAGUtilityAccount .
What is the property I should be checking for to determine which listed accounts are the "human" accounts, and which are machine accounts?
public static List<string> GetComputerUsers()
{
List<string> users = new List<string>();
var path =
string.Format("WinNT://{0},computer", Environment.MachineName);
using (var computerEntry = new DirectoryEntry(path))
{
foreach (DirectoryEntry childEntry in computerEntry.Children)
{
if (childEntry.SchemaClassName == "User")
{
users.Add(childEntry.Name);
}
}
}
return users;
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
the first code block here[^] seems to give actual user names.
|
|
|
|
|
Hi Luc,
The first code block gives me the strings, "INTERACTIVE" and "Authenticated Users".
And the second code block fails because I do not have an LDAP server on my LAN.
Thank you
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Hi,
Richard Andrew x64 wrote: What is the property I should be checking for to determine which listed accounts are the "human" accounts, and which are machine accounts? I believe your childEntry variable will be a IADsUser COM object[^] for end-user accounts. You may be able to perform additional filtering by inspecting the IADsUser properties[^].
I am not a C# developer so I don't know off the top of my head how you would access this. Looking at the documentation it appears that you would need to iterate through DirectoryEntry.Properties[^] to access properties like 'LastLogin'.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you David.
I'm not averse to using native code to access what I need.
Which functions would I use to do this?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: Which functions would I use to do this?
You are the C# developer not me.
See if this works:
foreach (DirectoryEntry childEntry in computerEntry.Children)
{
if (childEntry.SchemaClassName == "User")
{
IADsUser coronavirus = childEntry.NativeObject as IADsUser;
}
}
|
|
|
|
|
Thank you for your response.
There seems to be a misunderstanding. I was asking which native functions I would use to do this. I only want the local machine accounts.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
I've already told you how you need to go about doing this. You will need to come up with some criteria for filtering out some accounts using the method I mentioned above.
First let's get on the same page. Could you tell me what accounts are listed if you use the method I mentioned above to filter out all accounts with the AccountDisabled IADsUser Property[^]?
|
|
|
|
|
Randor wrote: First let's get on the same page.
OK when I filter out accounts that have AccountDisabled == true, I get the following:
admin <<- This is my account
SQLEXPRESS00 through SQLEXPRESS20 <- I have Sql Server Express installed
INTERACTIVE <- I don't know which user this is
Authenticated Users <- I don't know which user this represents
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard,
Great, that looks good. I mentioned AccountDisabled because typically 'Built-In' accounts have the disabled flag set to disallow network login.
But you are not enumerating user account objects. You are enumerating everything.
Now enumerate with the scope of'WinNT://YOUR_MACHINE/Administrators,group' and then 'WinNT://YOUR_MACHINE/Users,group'
Best Wishes,
-David Delaune
|
|
|
|
|
Hmmmm,
You haven't answered yet and since I am under forced quarantine/lockdown orders I threw this together for you. You will have to figure out how to translate it to C#
I apologize in advance for the nested IF statements. It's a code sample and I don't really feel like taking the time to make it look pretty.
#pragma comment(lib, "adsiid.lib")
#pragma comment(lib, "Activeds.lib")
#include <iostream>
#include <windows.h>
#include <atlbase.h>
#include <activeds.h>
#include <iads.h>
#include <adshlp.h>
#include <strsafe.h>
INT main()
{
IADsClass* pClass = NULL;
IADs* pADs;
BSTR bstrSchema;
VARIANT var;
IEnumVARIANT* pEnumerator = NULL;
IADsContainer* pContainer = NULL;
ULONG count;
IADs* pChild = NULL;
WCHAR ad_path[MAX_PATH] = { 0 };
WCHAR computer_name[MAX_COMPUTERNAME_LENGTH] = { 0 };
count = MAX_COMPUTERNAME_LENGTH;
GetComputerName(computer_name, &count);
count = MAX_PATH;
if (SUCCEEDED(CoInitialize(NULL)))
{
if (SUCCEEDED(StringCchPrintfW(ad_path, count, L"WinNT://%s,computer", computer_name)))
{
if (SUCCEEDED(ADsGetObject(ad_path, IID_IADsContainer, (void**)&pContainer)))
{
if (SUCCEEDED(ADsBuildEnumerator(pContainer, &pEnumerator)))
{
VariantInit(&var);
while (SUCCEEDED(ADsEnumerateNext(pEnumerator, 1, &var, &count)) && count == 1)
{
if (SUCCEEDED(V_DISPATCH(&var)->QueryInterface(IID_IADs, (void**)&pChild)))
{
BSTR bstrClass;
pChild->get_Class(&bstrClass);
if (CComBSTR(bstrClass) == CComBSTR(L"User"))
{
IADsUser* user = nullptr;
if (SUCCEEDED(pChild->QueryInterface(&user)))
{
VARIANT_BOOL is_disabled;
user->get_AccountDisabled(&is_disabled);
if (VARIANT_FALSE == is_disabled)
{
BSTR bstrName;
pChild->get_Name(&bstrName);
std::wcout << bstrName << std::endl;
SysFreeString(bstrName);
pChild->Release();
}
}
}
pChild->Release();
}
VariantClear(&var);
}
ADsFreeEnumerator(pEnumerator);
}
pContainer->Release();
}
}
}
CoUninitialize();
return 0;
}
Best Wishes,
-David Delaune
|
|
|
|
|
I apologize for not answering sooner. I was called away.
I thank you very kindly for that code sample.
I will have no problem using it as is. I can make a mixed mode executable.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi David,
I ran this code and it still lists all of the SQL Express users along with my username, "admin".
Windows has to know the difference somewhere. After all, when you go into the Settings app, it lists only the "human" users on the Manage Users page.
Thanks for any pointers.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi I am trying to develop a multitasking application in C# based on some code I have available that is depicted below. I have tried to do some changes but I am not sure if I put the WaitOne() and Release() methods at the correct places.
I am trying to include semaphore for a secure usage of common resources.
A semaphore is defined in C# by making a "Semaphore" variable, and use the methods WaitOne() and Release() to access the semaphore services.
I want to include name, student number and the semester year in the display information.
Sleep(0) statements can be used to test the sharing of common resources. I will use a console application.
The print out in console should be something like:
[T1]: Student no.
[T1]: Student name
[T1]: Semester year
[T2]: Student no.
[T2]: Student name
[T2]: Semester year
[T1]: Student no.
[T3]: Student no.
[T1]: Student name
[T2]: Student name
using System;
using System.Threading;
namespace ThreadSys
{
class ThreadClass
{
int loopCnt, loopDelay;
Thread cThread;
public string studentname;
static Semaphore semaphore = new Semaphore(1,1);
public ThreadClass(string name, int delay)
{
loopCnt = 0;
loopDelay = delay;
cThread = new Thread(new ThreadStart(this.run));
cThread.Name = name;
cThread.Start();
}
void run()
{
Console.WriteLine(" Starting " + cThread.Name);
do
{
loopCnt++;
Thread.Sleep(loopDelay);
Console.Write(" ");
semaphore.WaitOne();
Console.Write(cThread.Name);
Console.Write(": ");
Console.WriteLine("Loop=" + loopCnt);
semaphore.Release();
} while (loopCnt < 5);
Console.WriteLine(" Ending " + cThread.Name);
}
}
class ThreadSys
{
static void Main(string[] args)
{
Console.WriteLine(" Start of main program ");
ThreadClass ct1 = new ThreadClass("[T1]:", 95);
ThreadClass ct2 = new ThreadClass("[T2]:", 279);
ThreadClass ct3 = new ThreadClass("[T3]:", 463);
for (int cnt = 0; cnt < 30; cnt++)
{
Console.Write(".");
Thread.Sleep(100);
}
}
}
}
|
|
|
|
|
It's not really a very good test as there is nothing that is shared between the threads. You could try using a common memory buffer, where one thread puts data into it, and the other takes data out.
|
|
|
|
|
This is more of a simulation of a multitask application. The only thing I was trying to do here is to make some slight changes to the code so that I get print outs where Tasks [T1], [T2] and [T3] are not only printing out sequnetally but kind of roandomly in sort of random order.
However my C# coding abilites are worse than I would imagine so getting this done anytime soon aitn gonna happen.
Furthermore, I couldnt find anything on this Threadclass in C#. I didnt see any examples online where this ThreadClass was used directly in the code.
|
|
|
|
|
auting82 wrote: I couldnt find anything on this Threadclass in C#.
Of course you didn't. It's not part of the .NET Framework. It's code YOU WROTE, so why would you expect there to be any documentation on it anywhere?
Threads do not run in sequential order, and cannot be predicted to execute in any determined order. It's not the code that is wrong, but your expectations of how the system will execute it.
|
|
|
|