Re: Classic ADO & .NET

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Shock (no_at_way.com)
Date: 10/10/04


Date: Sun, 10 Oct 2004 13:47:08 -0500

Jerry Pisk wrote:
> You should pass the login and password either in the connection string or as
> parameters to Connection.Open() but not both.
>
> Jerry
>
> "Shock" <no@way.com> wrote in message
> news:10mgj6rm304g982@corp.supernews.com...
>
>>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
>
>
>

Just an update: I got it to work by declaring the User/Pass in the
connection string and passing nulls for those arguments in
connection.open(). Like so,

connection.open(conString, null, null, 0);

However, it's funny, it still won't work if I take the user/pass out of
the string and pass them in as arguments. Very strange, but I'm not too
worried about it. I will hard use classic ADO, so I'm just satisfied
with it working. Thanks for the help.

Shock



Relevant Pages

  • Re: Classic ADO & .NET
    ... Jerry Pisk wrote: ... > You should pass the login and password either in the connection string or as ... >>I haven't used 'Classic ADO' in years so I wouldn't be surprised if I was ...
    (microsoft.public.data.ado)
  • Re: Classic ADO & .NET
    ... You should pass the login and password either in the connection string or as ... Jerry ... > Hey guys, ... > I haven't used 'Classic ADO' in years so I wouldn't be surprised if I was ...
    (microsoft.public.data.ado)
  • Re: Classic ADO & .NET
    ... Jerry Pisk wrote: ... > You should pass the login and password either in the connection string or as ... >>I haven't used 'Classic ADO' in years so I wouldn't be surprised if I was ... I also defined my query and passed it to this method in the strQuery ...
    (microsoft.public.data.ado)
  • ADO.NET connection string creation using Dialogs.
    ... Is there any way in the new ado.net 2.0 to create a connection string using ... It was possible using the classic ado objects. ... Prev by Date: ...
    (microsoft.public.dotnet.framework.adonet)