[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Opening a connection using ODBCConnection

Tim B

5/17/2002 9:53:00 AM

Hi,
am trying to connect to a database for which i have an odbc driver.
Is it possible using ADO.NET?
When i attempt to open an ODBCconnection using the following string

Provider=MSDASQL.1;Password="";Persist Security Info=True;User ID=TIM;Data
Source=SageLine132

i get the following error

Microsoft.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified
at Microsoft.Data.Odbc.OdbcConnection.Open()
at System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
ConnectionState& originalState)
at System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at CsTest.Service1.SelectOdbcSrvRows(String connection, String query) in
c:\inetpub\wwwroot\cstest\service1.asmx.cs:line 57

Thanks in advance

Tim B




4 Answers

(Hussein Abuthuraya(MSFT))

5/18/2002 3:07:00 AM

0

Tim B

5/20/2002 5:51:00 PM

0

Hi Hussein,

1/ "SageLine132" is indeed a System DSN.
2/ If I create a data link via the database connection, I get a new data
connection created called "\." Below this under tables, all the tables i
expect to be available are in fact available.
3/For this project i wanted to create a simple webservice which allowed the
user to pass a SQL query as a string and the webservice would return the
dataset as xml. I can replicate this easily using SQL server.
4/If i use the Data connection i just created and drag it onto the
Sage.asmx.cs design window i get the following error message.
You cannot use an OLE DB Provider for ODBC connections.

I have tried the following code instead.


[WebMethod]

public DataSet HelloWorld(string sQuery)

{


DataSet DS = new DataSet();

try

{

OdbcConnection conn = new OdbcConnection("DSN=SageLine132;UID=TIM;PWD=;");

OdbcDataAdapter adapter = new OdbcDataAdapter();

adapter.SelectCommand = new OdbcCommand(sQuery, conn);

adapter.Fill(DS);

}

catch (Exception e)

{


throw e;

}

return DS;

}

Thanks in advance

Tim B



Tim B

5/20/2002 6:42:00 PM

0

Further to the previous mail. A exception is thrown when the adapter.fill
line is executed.

Message "ERROR [28000] User ID or Password invalid
ERROR [01000] The driver returned invalid (or failed to return)
SQL_DRIVER_ODBC_VER: 2.00
ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr
failed
ERROR [01000] [Microsoft][ODBC Driver Manager] The driver doesn't support
the version of ODBC behavior that the application requested (see
SQLSetEnvAttr)." string


Code is


[WebMethod]

public DataSet HelloWorld(string sQuery)

{


DataSet DS = new DataSet();

try

{

OdbcConnection conn = new OdbcConnection("DSN=SageLine132;UID=TIM;PWD=;");

OdbcDataAdapter adapter = new OdbcDataAdapter();

adapter.SelectCommand = new OdbcCommand(sQuery, conn);

adapter.Fill(DS);

}

catch (Exception e)

{


throw e;

}

return DS;

}



Incidentally the driver is a read only driver.


Thanks in advance

Tim




abnormal

6/18/2002 3:54:00 PM

0

"Hussein Abuthuraya(MSFT)" <HussAbOnline@microsoft.com> schrieb im
Newsbeitrag news:mhosjhg$BHA.2008@cpmsftngxa08...
> Do you want o connect from ASP page or Win FOrms? If ASP page then the
DSN need to be System DSN and not a User DSN. If it is a System DSN, make
sure that there is
> no user DSN with the same name.

You could not believe, how much this helped me.
I getting lots of errors and searching for resolutions everywhere, but
didn't know it have to be a System DSN.
Now I created a System DSN and my project finally works with Asp.Net :)

Thanks, thanks