S
sck10
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
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