none
Need right connection string for VB.NET (ODBC) RRS feed

  • Question

  • I'm converting an app from Delphi 7 to VB.NET
    I use an ADO connection with the following Connection string:
    Provider=MSDASQL.1;Extended Properties=

    "DSN=MyDSN;SERVER=MyBigServer;DATABASE=MyDatabase;UID=MyUserID;PWD=MyPasswd"
    It works fine in the Delphi app.
    (Names have been changed to protect the guilty - Dragnet)
    The ADO, in turn, uses ODBC, So I went straight to ODBC in the VB app.

    In VB.Net I have this code:

    Private oConn As OdbcConnection = New OdbcConnection()
    ...
    Dim S As String = My.Settings.MyConnection
    'That is the connection string that worked in Delphi

    oConn.ConnectionString = S
    oConn.Open()

    At Open I get this error:
    ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

    How do I modify the connection string, and/or other settings, to make this work in VB.Net (2005)?

    Thanks,
    Jon

    Friday, September 12, 2008 7:47 PM

Answers

  • You are using OLEDB for ODBC provider and it is not supported by ADO.NET. Actually it was never supported from the beginning of ADO.NET. In addition you are using OLEDB-type string with ODBC managed provider provider, which is also not correct. What kind of database are you connecting to? If it is SQL Server then you could use .NET Managed Provider for SQL Server (SqlConnection and other Sql... classes). If it is some sort of database that has only ODBC driver or OLEDB provider, you could use OdbcConnection or OleDbConnection to connect to your database. Here is the web site with samples of connection strings

     

    http://www.carlprothman.net/Default.aspx?tabid=81

     

    Monday, September 15, 2008 9:49 AM
    Moderator

All replies

  • You are using OLEDB for ODBC provider and it is not supported by ADO.NET. Actually it was never supported from the beginning of ADO.NET. In addition you are using OLEDB-type string with ODBC managed provider provider, which is also not correct. What kind of database are you connecting to? If it is SQL Server then you could use .NET Managed Provider for SQL Server (SqlConnection and other Sql... classes). If it is some sort of database that has only ODBC driver or OLEDB provider, you could use OdbcConnection or OleDbConnection to connect to your database. Here is the web site with samples of connection strings

     

    http://www.carlprothman.net/Default.aspx?tabid=81

     

    Monday, September 15, 2008 9:49 AM
    Moderator
  • Another good resource for connection strings: http://www.connectionstrings.com

    Monday, September 15, 2008 9:31 PM
  • Thank you for your reply.

     

    >using OLEDB-type string with ODBC managed provider provider, which is also not correct

    Yes, I know the Delphi string is not correct for .NET ODBC. That's my question: how to take the information in the old string and format it properly for the new.

     

    >What kind of database are you connecting to?

    I wish I could find out.

     

    >If it is some sort of database that has only ODBC driver

    That's what I was trying to say. I guess I could have been clearer.

     

    >use OdbcConnection

    That's what I used in my vb app, and in my sample code.

     

    Thank you for the link. I will see if I can figure it out from that.

     

    Jon
    Tuesday, September 16, 2008 3:52 AM
  • Thank you for the link. I will see if I can figure it out from that.

     

    Jon

    Tuesday, September 16, 2008 3:54 AM
  • You need to post type of database you are trying to create connection to and then someone would be able to help you with the connection string.
    Tuesday, September 16, 2008 9:53 AM
    Moderator
  • >You need to post type of database you are trying to create connection to

     

    I didn't orignally have that information, just the connection string in a working Delphi app.

     

    I did learn the type of database, sort of. It is Cache. With that info and the links provided, I built a connection string from the old (Delphi) one, and it works!

    Old ConnectionString:
    Provider=MSDASQL.1;Extended Properties=

    "DSN=MyDSN;SERVER=MyBigServer;DATABASE=MyDatabase;UID=MyUserID;PWD=MyPasswd"


    New:
    "DRIVER=InterSystems ODBC;Dsn=MyDSN;SERVER=MyBigServer;DATABASE=MyDatabase;uid=MyUserID;MyPasswd"


    Basically unchanged, except for replacing provider and extended properties clauses with a Driver clause.

     

    Note: examples I saw in the links used addresses like 123.456.78.9 but using a named server and database worked for me.
    I mention this in case someone else Googles for a solution to such a problem.

    Jon

     

    Wednesday, September 17, 2008 7:52 PM
  • you can try it in oledb connection.

     

    http://vb.net-informations.com/ado.net-dataproviders/ado.net-oledbconnection.htm

     

    thnaks.

    leveena.

     

    Tuesday, November 25, 2008 3:57 AM