"Classic ADO" & C#

  • Thread starter Thread starter Shock
  • Start date Start date
S

Shock

Hey guys,

I'm trying to connect to an SQL Server Database using classic ado in
VS.Net using the C# lang. I am using the Microsoft ActiveX Data Objects
Library version 2.8. Here is the code I've written so far.

public ADODB.Recordset getRecordSet(string strQuery)
{
ADODB.Connection adodbcon = new Connection();
int intOptions = ((int)ADODB.CommandTypeEnum.adCmdTable);
string conString = "Provider=SQLOLEDB;Initial Catalog=cperkins;Data
Source=(local)\\AgC;User ID=sa;";
string strUser = "sa";
string strPassword = string.Empty;
adodbcon.Open(conString, strUser, strPassword, intOptions);

ADODB.Command adodbcom = new Command();
adodbcom.CommandText = strQuery;
adodbcom.CommandType = ADODB.CommandTypeEnum.adCmdText;

ADODB.Recordset adodbrs = new ADODB.Recordset();
adodbrs.Open(adodbcon, adodbcom, ADODB.CursorTypeEnum.adOpenDynamic,
ADODB.LockTypeEnum.adLockBatchOptimistic,
(int)ADODB.CommandTypeEnum.adCmdTable);

return adodbrs;
}

The I get this error, "Arguments are of the wrong type, are out of
acceptable range, or are in conflict with one another.", on the
adodbcon.open statement.

I haven't used 'Classic ADO' in years so I wouldn't be surprised if I
was doing something completely asinine. Thanks ahead for any help.

Shock
 
Back
Top