|
You can use DirectoryEntry to achieve this. Here's a sample piece of code:
public void FindUser(String userName)
{
DirectoryEntry entry = GetDirectoryEntry();
DirectorySearcher search = new DirectorySearcher(entry);
string filter = string.Format("(&(ObjectClass=user)(cn='{0}'))", userName);
search.Filter = filter;
foreach (SearchResult result in search.FindAll())
{
try
{
System.DirectoryServices.DirectoryEntry de = result.GetDirectoryEntry();
Console.WriteLine("WhenCreated : " + de.Properties["WhenCreated"].Value.ToString());
Console.WriteLine("User Name : " + de.Properties["sAMAccountName"].Value.ToString());
}
catch (Exception ex)
{
}
}
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
Hi Folks,
I'm hoping someone can assist me with a (hopefully) simple question. Is there a way to query a database to get the type of the parameters expected by a stored proc, or the column types of a table. I know this can be done through SQL for most databases (e.g. see below, for SQL Server Column Types), but want a solution which works with any database.
SELECT name
from sys.types
where user_type_id in
(
select user_type_id
from sys.columns
WHERE object_id = OBJECT_ID('@schemaName.@tableName')
and name='@columnName'
)
Background
For anyone wanting to know more about why I'd need this, here's a little more info on what I'm attempting.
I'm writing a web service, which can act as a wrapper to any databases. The databases' connection strings will be included in the config file, using the MS Enterprise Library, so that when a call is made, the name of the DB can be included, which can then be used to get the appropriate connection.
Reading information is pretty simple; given the database name and the table / (parameterless) stored proc name the code reads from that object, and outputs data in the format <tableOrProcName><row><fieldName>...</fieldName>...</row>...</tableOrProcName>.
However, when performing inserts (and other operations where I'd need to be cognizant of data types), I'd like to query the database to get a list of expected parameter/column names and types, which I can then cross reference with the names of the XML 'Field' elements, to convert the values from strings to the correct types before populating the commandText / parameter.
Once coded, I'll make the solution available on here for anyone looking to do the same.
(For anyone wondering why we'd need a wrapper for databases, the answer is many programs these days come with simple methods for attaching to web service calls, but don't provide similar features for databases, so this is a simple & flexible workaround. Security is not an issue, since both the webservice and database are configured to only allow the service account access, so users can't use the service as a backdoor).
Thanks in advance,
JB
modified on Monday, June 14, 2010 7:50 AM
|
|
|
|
|
I get a DataReader* and use its GetSchemaTable method -- it works on all the databases I've used so far.
* I use a query like "SELECT ... FROM ... WHERE 0=1 " so the DataReader doesn't unnecessarily retrieve any data.
|
|
|
|
|
Ahh that's great - thanks for the info. It took me a bit of time to realise that columns were rows in the schema, so I've chucked some sample code below for anyone looking to do something similar:
DbConnection con = new SqlConnection(connectionstring);
DbCommand command = con.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = "select * from dbo.DemoTable where 0=1";
command.Connection.Open();
using (IDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
{
DataTable table = reader.GetSchemaTable();
foreach(DataRow row in table.Rows)
{
Console.WriteLine(string.Format("{0}: {1}", row.Field<string>("ColumnName"), row.Field<Type>("DataType").ToString()));
}
}
command.Connection.Close();
Console.WriteLine("Done");
Console.ReadKey();
However, this won't work for getting the input parameters for a stored proc. Do you know of an equivelant to the following?
SELECT name
from sys.types
where user_type_id in
(
select user_type_id
from sys.parameters
WHERE object_id = OBJECT_ID('@schema.@storedProc')
and name='@paramName'
)
Thanks again for your help so far; it's very much appreciated.
Kind regards,
JB
|
|
|
|
|
Inverso1 wrote: for getting the input parameters for a stored proc
That would depend on the database; not all of them support them.
|
|
|
|
|
Hello, I am working in visual studio to make a project which requires using lists. I need a little help to complete this. The first thing I need to know is how to select a top result in a list, so that its highlighted, just like when you click. How would I code this so that it works with the down arrow, I know you use keycode etc, but can’t figure out the way to highlight it …. Then when I press enter I want to select the list item… Thanks…
Next, I have two forms and trying to make a “find and replace” function, so this requires looking on a richtextbox in the first form and when a button is clicked on the find and replace form it should effect it. My question is however, how do you connect to another form ? because I have no idea what to do ….
Last question, I need to know a quickly print and print preview a rich text box, thanks for all your help
Steve
|
|
|
|
|
SRJ92 wrote: The first thing I need to know is how to select a top result in a list, so that its highlighted, just like when you click.
Sounds like a ListBox [^]. The link also has a code-example on selecting specific items.
SRJ92 wrote: Then when I press enter I want to select the list item…
I believe that you can do that already using the space-bar, allowing for multiple selections. Perhaps you could replace the "return"-keypress with a space-character?
SRJ92 wrote: My question is however, how do you connect to another form ?
You'd "show" Form2 from Form1 . Information can be passed by creating additional properties in Form2.
SRJ92 wrote: I need to know a quickly print and print preview a rich text box
That's not supported out of the box - you'd either need to program it or find a third-party product to provide that functionality.
I are Troll
|
|
|
|
|
how exactly do i "show" Form 1 to Form 2 ?? Thanks
|
|
|
|
|
By calling the Show[^] method of the form;
Form1 myForm = new Form1();
void Button1_Click(object sender, EventArgs e)
{
myForm.Show(this);
} Although I'd prefer names like "MainForm" and "SearchAndReplaceForm"
I are Troll
|
|
|
|
|
Hi ,
Might be a simple fix, but struggling for a long time.
I have built a new site and configured that in IIS, whenever I login to the server I get the "Connect to" windows login dialog. However on pressing cancel in this dialog, te screen loads without any issues.
Any idea how i can get rid of this?
Ramki
|
|
|
|
|
See title.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Try the ASP.NET forum.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Thank you and sorry about that
Jack Sparrow
--------------------------------------
Defeat is not the worst of failures. Not to have tried is the true failure.
|
|
|
|
|
I am creating an email service but the email service needs to be very scalable with almost nodowntime as it will be sending thousands of email every hour after checking the user from database.
Is there any architecture for creating such kind of services.
|
|
|
|
|
You are sending thousands of emails per hour to the same user!?!
Please, tell me how I stay off your mailing list!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
No we are not sending to one user but many users.
|
|
|
|
|
Hey
Im having a problem using the sockets asynchronous BeginSend method. My server application is sending a large amount of data in small chunks and therefore I am calling BeginSend many times in a short period of time. I believe that the recieving application cant handle the speed and therefore the sender is queuing the calls until they can be sent. This means that memory is constantly increasing on the sender application. I think that I need to implement some sort of flow control to stop calling BeginSend when there are to many calls pending. Can anyone help me out or point me to some literature on this issue?
Thanks
|
|
|
|
|
This is the pattern I'm familiar with (in pseudocode):
Socket socket;
Queue<Data> pendingData;
bool sending;
public void SendAsync (Data data)
{
if (sending)
{
pendingData.Add(data);
}
else
{
sending = true;
socket.BeginSend(data, new Callback(SendCallback));
}
}
private void SendCallback ()
{
socket.EndSend();
if (pendingData.Count > 0)
{
socket.BeginSend(pendingData.DequeueReasonableAmountOfData(), new Callback(SendCallback));
}
else
{
sending = false;
}
}
This maintains only one outstanding asynchronous send operation at a time and the amount of data queued to be sent can easily be handled by user code. This is useful in case the queued data needs to be resent if the client disconnects/reconnects, or if you want to put a limit on how much data to queue to send or perhaps prioritize the queued data in some way.
Of course another important part would be to make sure the receiver is receiving in such a way that parsing the data isn't blocking the socket from immediately receiving the next packet being sent.
|
|
|
|
|
Thanks this is exactly what I needed.
|
|
|
|
|
You're welcome
|
|
|
|
|
Hi. I noticed that when creating a localized application (by separating languages in interface) compiler creates subfolders for those languages and places the DLLs in them. I am trying to find a way to implement these DLLs in the Application assembly and avoid the need of subfolders for these DLLs,
Please advice.
Thanks.
|
|
|
|
|
The reason that it places them in subfolders is so that the runtime can pick the relevant one up - basically, the name of the folder follows a special naming convention which allows the localisation code to pick up a specific culture if it's available, drop back to the language if it's not, and then fall back to the default language if that's not available.
Trying to circumvent this means that you will have to code the infrastructure yourself. What business reason do you have for wanting to do this?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks pete. I Realize that. I just wonder if there is a way to implement it in one assembly.
|
|
|
|
|
Hi all,
I have an application that was written in C# (VS 2005). The applications reads properties of ms office documents and for that purpose it uses the dsofile.dll (version 2.1) library from Microsoft. Now I'm trying to port my app. to VS 2008. But the problem is that when I try to add a reference to dsofile I get an error stating that 'Can't add a reference to the file. Please verify that the file is a valid assembly or a COM component.' Can someone please help me with it..?
Regards
Ankit.
===========================
It's done people. The problem was due to file permissions. I downloaded another copy from Microsoft and replaced the original file, and it's working fine now.
-- Modified Monday, June 14, 2010 5:49 AM
modified on Monday, June 14, 2010 5:54 AM
|
|
|
|