473,396 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ADODB to ADO.NET conversion

Hello,

I am using the following in ASP.NET 2.0 VB using ADODB (which is working).
I would like to convert this to csharp using ADO.NET.

To build the connection, I am trying to convert:

LDAP_CONN = CreateObject("ADODB.Connection")
LDAP_CONN.Provider = "ADsDSOObject"
LDAP_CONN.Open()
LDAP_COM = CreateObject("ADODB.Command")
LDAP_COM.ActiveConnection = LDAP_CONN
RS = LDAP_CONN.Execute(strSQL)

to

OleDbConnection conn = new OleDbConnection("ADsDSOObject");
OleDbDataReader rdr = null;
conn.Open();
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
rdr = cmd.ExecuteReader();

When I run this, I get the following error:

Format of the initialization string does not conform to specification
starting at index 0 (for OleDbConnection conn = new
OleDbConnection("ADsDSOObject");).

Also, should the value that I have for LDAP_CONN.Provider = "ADsDSOObject"
be used for the OleDbConnection?

Any help with this would be appreciated. Thanks, sck10

VB Code
-----------------

Dim stlPost As SortedList = New SortedList()
Dim strValue As String = ""
Me.lblMessageText.Text = ""

Dim LDAP_CONN As Object, LDAP_COM As Object, RS As Object
Dim tmp As Object = "", Item As Object = ""

Dim strFields As String = "ntUserDomainId, employeeNumber, uid, cn,
telephonenumber, mail "
Dim strLDAP As String =
"'LDAP://ldap-uscentral.post.MyCompany.com:389/o=MyCompany.com/ou=people' "
Dim strWhere01 As String = "WHERE employeenumber='" & strHRID & "' "
Dim strWhere02 As String = "OR uid='" & strHRID & "'"
Dim strSQL As String = "SELECT " & strFields & " FROM " & strLDAP &
strWhere01 & strWhere02 & " ORDER BY sn"

Try
LDAP_CONN = CreateObject("ADODB.Connection")
LDAP_CONN.Provider = "ADsDSOObject"
LDAP_CONN.Open()
LDAP_COM = CreateObject("ADODB.Command")
LDAP_COM.ActiveConnection = LDAP_CONN
RS = LDAP_CONN.Execute(strSQL)

For Each Item In Split(Replace(strFields, " ", ""), ",")
tmp = RS(Item).Value
strValue = tmp(0).ToString
If Item.ToString = "ntUserDomainId" Then strValue = tmp ' Can't handle
"\" in domain\sck10
stlPost.Add(Item.ToString, strValue)
'Me.lblPost.Text &= Item.ToString & ": " & tmp(0).ToString & "<br />"
'Response.Write(Item & ": " & tmp(0) & "<br />") 'If Not
IsNull(tmp) Then Response.Write(tmp(0))
Next

stlPost.TrimToSize() ' Trim the list

'Asign values from Array
Dim strCN As String = stlPost("cn").ToString
Me.hdnLDAPLastName.Value = Trim(Left(strCN, InStrRev(strCN, ",") - 1))
Me.hdnLDAPFirstName.Value = Trim(Mid(strCN, InStrRev(strCN, ",") + 1))
Me.hdnLDAPEmail.Value = Trim(stlPost("mail").ToString)
Me.hdnLDAPTelephone.Value = Trim(stlPost("telephonenumber").ToString)

Catch ex As Exception
Me.pnMessage.Visible = True
End Try
Sep 19 '06 #1
4 3295
Hello Steve,

From the code snippet you provided, you used to use the OLEDB provider to
query some LDAP directory storage and want to uprade the code into .NET
code, correct?

Based on my experience, in .net framework, the classes under the
System.DirectoryServices namespace are the prefered ones for manipulating
LDAP , ActiveDirectory service. For your scenario, if you want to query
some objects from a LDAP storage, you can use the "DirectorySearcher" class
which can be constructed with a LDAP connectionstring and some additional
search filter or optional properties. e.g.

#the following function use DirectorySearcher to query the user objects in
the domain
==========================
Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnQuery.Click

Response.Write("<br/>btnQuery_Click.............")

Dim connstr =
"LDAP://fareast.corp.microsoft.com/OU=UserAccounts,DC=fareast,DC=corp,
DC=Microsoft, DC=com"
Try

Dim entry As New
DirectoryEntry("LDAP://fareast.corp.microsoft.com/OU=UserAccounts,DC=fareast
,DC=corp, DC=Microsoft, DC=com")
Dim mySearcher As New DirectorySearcher(entry)

mySearcher.Filter =
"(&(objectCategory=person)(objectClass=user)(Displ ayname=Steven Cheng))"
Dim mySearchResult As SearchResultCollection =
mySearcher.FindAll()

Dim result As SearchResult = mySearchResult(0)
Dim item As DirectoryEntry = result.GetDirectoryEntry()

Response.Write("<br/>Name: " & item.Name)
For Each props As PropertyValueCollection In item.Properties

Response.Write("<br/>" & props.PropertyName & ": " &
props(0).ToString())

'if you want to print out all the property values
'If (props.Count 0) Then
' For Each obj As Object In props
' Response.Write("<br/>&nbsp;&nbsp;&nbsp;&nbsp;" &
obj.ToString())

' Next
'End If

Next

Catch ex As Exception

Response.Write("<br/>" & ex.ToString())
End Try

End Sub
===================================

here are some other good reference and examples about ADSI programming
through VB.NET:

#Quick List for Visual Basic 2005 Code Examples
http://msdn2.microsoft.com/en-us/library/ms180834.aspx

#Active Directory and VB.NET
http://www.vbdotnetheaven.com/Upload...ectoryInVB1112
2005060642AM/ActiveDirectoryInVB.aspx?ArticleID=a775db4b-3909-4d36-86e2-917b
6d693465

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 20 '06 #2
Steven,

Thank you very much for your help.

I got it to work, but I had to add:
entry.AuthenticationType = AuthenticationTypes.None;

Is this the default? I noticed that a lot of the examples on the web
don't show this in their examples.

Thanks again, sck10

try
{
DirectoryEntry entry = new
DirectoryEntry("LDAP://ldap-uscentral.post.lucent.com:389/o=lucent.com/ou=people");
entry.AuthenticationType = AuthenticationTypes.None;
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectclass=person)(employeenumber=" + HRID +
"))";
SearchResultCollection mySearchResult = mySearcher.FindAll();
SearchResult result = mySearchResult[0];
DirectoryEntry item = result.GetDirectoryEntry();

foreach(PropertyValueCollection props in item.Properties)
{
Response.Write("<br />" + props.PropertyName + ": " +
props[0].ToString());
}
} // end try


"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:rV**************@TK2MSFTNGXA01.phx.gbl...
Hello Steve,

From the code snippet you provided, you used to use the OLEDB provider to
query some LDAP directory storage and want to uprade the code into .NET
code, correct?

Based on my experience, in .net framework, the classes under the
System.DirectoryServices namespace are the prefered ones for manipulating
LDAP , ActiveDirectory service. For your scenario, if you want to query
some objects from a LDAP storage, you can use the "DirectorySearcher"
class
which can be constructed with a LDAP connectionstring and some additional
search filter or optional properties. e.g.

#the following function use DirectorySearcher to query the user objects in
the domain
==========================
Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnQuery.Click

Response.Write("<br/>btnQuery_Click.............")

Dim connstr =
"LDAP://fareast.corp.microsoft.com/OU=UserAccounts,DC=fareast,DC=corp,
DC=Microsoft, DC=com"
Try

Dim entry As New
DirectoryEntry("LDAP://fareast.corp.microsoft.com/OU=UserAccounts,DC=fareast
,DC=corp, DC=Microsoft, DC=com")
Dim mySearcher As New DirectorySearcher(entry)

mySearcher.Filter =
"(&(objectCategory=person)(objectClass=user)(Displ ayname=Steven Cheng))"
Dim mySearchResult As SearchResultCollection =
mySearcher.FindAll()

Dim result As SearchResult = mySearchResult(0)
Dim item As DirectoryEntry = result.GetDirectoryEntry()

Response.Write("<br/>Name: " & item.Name)
For Each props As PropertyValueCollection In item.Properties

Response.Write("<br/>" & props.PropertyName & ": " &
props(0).ToString())

'if you want to print out all the property values
'If (props.Count 0) Then
' For Each obj As Object In props
' Response.Write("<br/>&nbsp;&nbsp;&nbsp;&nbsp;" &
obj.ToString())

' Next
'End If

Next

Catch ex As Exception

Response.Write("<br/>" & ex.ToString())
End Try

End Sub
===================================

here are some other good reference and examples about ADSI programming
through VB.NET:

#Quick List for Visual Basic 2005 Code Examples
http://msdn2.microsoft.com/en-us/library/ms180834.aspx

#Active Directory and VB.NET
http://www.vbdotnetheaven.com/Upload...ectoryInVB1112
2005060642AM/ActiveDirectoryInVB.aspx?ArticleID=a775db4b-3909-4d36-86e2-917b
6d693465

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 20 '06 #3
Thanks for your reply Steve,

Glad that you've got it working.

Yes, the DirectoryEntry.AuthenticationType is default to "Secure".
Actually, it is in .net framework 2.0 that has changed the default value to
"Secure", in previous versions, the default value is "None".

#DirectoryEntry.AuthenticationType Property
http://msdn2.microsoft.com/en-us/lib...ces.directorye
ntry.authenticationtype.aspx

I think that's why you've found many examples that didn't mention
this(since they're dedicated to .net 1.x).

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 21 '06 #4
Thanks Steven,

Cheers, sck10

"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:Yo**************@TK2MSFTNGXA01.phx.gbl...
Thanks for your reply Steve,

Glad that you've got it working.

Yes, the DirectoryEntry.AuthenticationType is default to "Secure".
Actually, it is in .net framework 2.0 that has changed the default value
to
"Secure", in previous versions, the default value is "None".

#DirectoryEntry.AuthenticationType Property
http://msdn2.microsoft.com/en-us/lib...ces.directorye
ntry.authenticationtype.aspx

I think that's why you've found many examples that didn't mention
this(since they're dedicated to .net 1.x).

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: KLomax | last post by:
I have a VB6 com object that uses ADO 2.1 for data access. I have referenced this object in a aspx application. It works fine on my local development machine. On our staging server, it errors when...
1
by: Sandie Towers | last post by:
We use a number of similar databases and frequently create a new database using a backup restore of another similar database. We try to keep changes between databases in _Additional tables - like...
0
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a...
3
by: Lance Geeck | last post by:
I sent this yesterday, but it hasn't made it into the news group, so I am re-sending it. The first one will probably showup 2 seconds after I hit the send button. Anyway, I am new to .net and...
3
by: Yuk Tang | last post by:
I'm trying to grab the fieldnames and values from a recordset, but I'm getting errors. I have an idea what the error might come from, but I'm not sure how to correct it. I'm connecting to an...
7
by: boyleyc | last post by:
Hi all I have written a database in access and used ADODB recordsets all the way through. The only recordsets that are not ADODB are the listbox navigation code automatically generated by access...
0
by: Katit | last post by:
Basically, I need to return data for legacy app in a way of ADODB.Recordset. http://support.microsoft.com/kb/316337 This article pretty much covers it, but I would like to do that without...
1
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I am involved in migrating a sizeable vb6 application to vb.net but don't want to add the extra complexity of migrating adodb to ado.net. Is this a sensible approach and if not what are the...
5
by: muriwai | last post by:
Hi, I have a C# assembly project under Visual Stuio 2008 Pro on Windows Server 2008. I converted the project from VS 2005. The project references COM->Microsoft CDO for Windows 2000 Library...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.