Page 1 of 2 12 LastLast
Results 1 to 40 of 48

Thread: [RESOLVED] This code won't open database connection in vs2008, it does work in vb6

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Resolved [RESOLVED] This code won't open database connection in vs2008, it does work in vb6

    I am typing in correct parameters
    vs2008 error complains that data source name not found, and no default driver specified
    I also notice now project reference management in vs2008 is horrible, I don't even see a way to remove any, seems you can only add them?
    vs2022 has a decent project references IDE that looks and works like vb6. Is anyone familiar with that?

    Maybe this sub will work in vs2022

    This works in vb6 program I am converting over
    in vb6, I do not have to type in a database name, what I do is make a database connection first, get the list of databases in the server,
    and it loads them into the combo box. A user selects the one they want, and it makes a connection and moves on into the app.

    So what am I missing? My program just has a reference to ADODB in the .net section in vs2008, tried to add one in the com section and 78 errors pop up,

    I dont know how to remove a project reference in vs2008?


    Code:
        On Error GoTo errhandler
    
            'construct a connection string from listed text in the boxes
            'leave it here this will be overwriten??
            provider1 = "Provider=" & _Text1_0.Text & ";"
            driver1 = "DRIVER=" & _Text1_1.Text & ";"
            host1 = "SERVER=" & _Text1_2.Text & ";"
            dbname1 = "DATABASE=" & Combo1.Text & ";"
            user1 = "UID=" & _Text1_4.Text & ";"
            pass1 = "PASSWORD=" & _Text1_5.Text & ";"
            port1 = "PORT=" & _Text1_6.Text & ";"
            opt1 = "OPTION=" & _Text1_7.Text & ";"
    
            frmlogonConnectstring = provider1 & driver1 & dbname1 & host1 & user1 & pass1 & port1 & opt1
    
                
            'test the connection
            Dim Con1 As New ADODB.Connection
            Dim NoError As Boolean
            Con1.ConnectionString = frmlogonConnectstring
            Con1.Open()
            'if no error
            NoError = True

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    What is this???

    it tells you nothing in vs2008?
    I 'think' the reference was to net adodb, and not a com reference to ado 2.8 or the like
    Am I looking in the wrong place to check the references?

    No checkboxes just lists, nothing to do?
    Attached Images Attached Images  

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,621

    Re: This code won't open database connection in vs2008, it does work in vb6

    Any particular reason that you are not using ado.net?

    https://learn.microsoft.com/en-us/tr...-data-provider
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sapator View Post
    Any particular reason that you are not using ado.net?

    https://learn.microsoft.com/en-us/tr...-data-provider
    Totally unfamiliar with it, will it require massive changes to the code?
    Right now I am just trying to get stuff working, this is a learning experience.

    I found the project reference removal box, it is under the properties menu
    So I removed adodb in the NET section and added in the COM section activeX ADO 6.1 library

    But still cant open database connection
    Will need to read up on what I am missing, it could be vs2008, I already found vs2022 works better on getsetting for example regarding non typeable chars in a reg setting, vs2008 does not work at all for that.

  5. #5
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,621

    Re: This code won't open database connection in vs2008, it does work in vb6

    It's not that different , you do the connection and I suppose (not seen your code) an iteration of the items with a datareader.
    If this is a learning experience you are not really learning anything using a highly depreciated call. As you can see, you are struggling to get something to work that already works and is included in vs2008.
    But your choice...
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,146

    Re: This code won't open database connection in vs2008, it does work in vb6

    I would also go with ADO.NET, but it might require significant changes. When I was working in VB6, I wasn't using ADO. I was using DAO, and I'm not sure how different those two are. I suspect that DAO may be closer to ADO than either is to ADO.NET, though.

    Database work in VB6 tended to follow the model of connecting to the DB and working with it in some way. In ADO.NET, you generally connect to the DB, suck the data into local memory, then close the connection. You then work with what you have in memory, and if necessary, then push changes back to the DB. It's a model that largely separates the DB from the program, with only temporary, relatively light, interactions.

    If you were using recordsets in ADO, then you'd probably be using a dataadapter or a datareader to pull data into a datatable in place of that. That could require quite different code for those areas, or a different design of the program in general. Exactly how much effort it would be is hard to say. It might be trivial, it might be extreme.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sapator View Post
    It's not that different , you do the connection and I suppose (not seen your code) an iteration of the items with a datareader.
    If this is a learning experience you are not really learning anything using a highly depreciated call. As you can see, you are struggling to get something to work that already works and is included in vs2008.
    But your choice...
    I suppose it is related to my connection is using ODBC style connections

    Oh, yes everything is a learning experience, even using older stuff.

    Mysql has a vbnet example for ODBC, but the item in red gives a warning says

    Warning 12 Namespace or type specified in the Imports 'Microsoft.Data.Odbc' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. C:\vbnetJess1\WindowsApplication1\WindowsApplication1\frmOpener.vb 5 9 sdlsconverted

    how to resolve that?
    See, I am not going to get anywhere fast unless I can see something working that should work.
    I just want to see it connecting a database and showing column values on the screen right now with no major rewrite.
    I am not a skilled vbnet programmer.
    I can imagine switching to ADO.NET the entire everything will all fail unless recoded to use that.
    I just don't want to do it as I have no clue to using ADO.net

    The project had a ref to adodb under the NET section so I figure must have been ADO.net reference and nothing worked for the DB conns.



    Imports Microsoft.Data.Odbc
    Imports System


    https://dev.mysql.com/doc/connector-...ng-net-vb.html

  8. #8
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,621

    Re: This code won't open database connection in vs2008, it does work in vb6

    I'm not sure I can help with ODBC but a lot of people will help if you are using the ado.net.
    I'm curious on what is the next lines of code you are using on manipulating the data. Let's say that you are connected to the database. What is the next step? Iteration? Some strange VB6 coding? As SH said it could be major or it could just take 5 minutes. I'm guessing the later but without code we cannot be sure.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sapator View Post
    I'm not sure I can help with ODBC but a lot of people will help if you are using the ado.net.
    I'm curious on what is the next lines of code you are using on manipulating the data. Let's say that you are connected to the database. What is the next step? Iteration? Some strange VB6 coding? As SH said it could be major or it could just take 5 minutes. I'm guessing the later but without code we cannot be sure.
    found this, I installed Mysql-NET connector
    However the example code given has the same namespace type error with MySql lines

    Imports System.Data

    Imports MySql.Data
    Imports MySql.Data.MySqlClient

    How do you connect to a mysql database?, Maybe if I can at least connect, I can understand, but so far all web examples fail.


    https://stackoverflow.com/questions/...sql-connection

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Here it says you have to buy a connector?? from DEVART?
    https://stackoverflow.com/questions/...2022-for-mysql

    in my vb6 version, I have it setup to easily switch and connect to MS-SQL, MySQL, MaAriaDB
    Makes no sense to me you have to purchase something to make it work.

  11. #11
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    If you want to use odbc to connect to a database then you would need to add a reference to System.Data.Odbc.dll - this is the library that contains the relevant odbc classes such as OdbcConnection

    The MySql.Data.MySqlClient is going to be a .net library that uses the .net approach e.g. DataReaders, DbConnections, DataAdapters etc.

  12. #12
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,801

    Re: This code won't open database connection in vs2008, it does work in vb6

    You will want to use the MySql.Data.MySqlClient namespace like you're doing in post #9.

    The basic gist to load every record in a Table into a DataTable is that you:
    1. Create a database connection
    2. Create a database command
    3. Create a database adapter
    4. Create a new DataTable
    5. Load the data from the adapter into the DataTable


    Here is a simplified example:
    Code:
    Dim table = New DataTable()
    Using connection = New MySqlConnection("my connection string")
        Using command = New MySqlCommand("SELECT * FROM MyTable", connection)
            Using adapter = New MySqlDataAdapter(command)
                connection.Open()
                adapter.Fill(table)
            End Using
        End Using
    End Using
    
    ' table now contains every record
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Actually find this a little bizarre.
    Do you really have to pay money for vbnet ADO.Net connections to say MariaDB?
    I don't believe it.
    https://marketplace.visualstudio.com...ADONETProvider

  14. #14
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    Actually find this a little bizarre.
    Do you really have to pay money for vbnet ADO.Net connections to say MariaDB?
    I don't believe it.
    https://marketplace.visualstudio.com...ADONETProvider

    You are not paying for anything specific to VB.Net (if you are paying for anything at all). The MySql provider is a 3rd party component and it would be down to the 3rd party to decide if it is free or not. Given MySql is owned by Oracle they may choose to charge for their provider. This is no different to a database manufacturer potentially charging for their ODBC driver. As an example the same company has ODBC drivers that aren't free - https://www.cdata.com/drivers/mysql/odbc/

    There might be other 3rd part options or open source providers, I don't use MySQL normally and wouldn't know what options are available if I am being honest.
    Last edited by PlausiblyDamp; Apr 22nd, 2024 at 10:19 AM.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by PlausiblyDamp View Post
    You are not paying for anything specific to VB.Net (if you are paying for anything at all). The MySql provider is a 3rd party component and it would be down to the 3rd party to decide if it is free or not. Given MySql is owned by Oracle they may choose to charge for their provider. This is no different to a database manufacturer potentially charging for their ODBC driver. As an example the same company has ODBC drivers that aren't free - https://www.cdata.com/drivers/mysql/odbc/

    There might be other 3rd part options or open source providers, I don't use MySQL normally and wouldn't know what options are available if I am being honest.
    Well, I will keep on learning with vbnet

    I set the program to use MSSQL server and it is working fine, gets the data from all the tables I made.
    Now with MSSQL, my program is set to what back in the day is called NT security, no passwords are used.
    It also has the capability to use MS Sql Server security with an assigned user name and password, which i set by the management console whatever made by MS.

    But HEY, you know it actually connects fine to MSSQL, which kind of shocked me as I have been banging head on wall with this database stuff today.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by dday9 View Post
    You will want to use the MySql.Data.MySqlClient namespace like you're doing in post #9.

    The basic gist to load every record in a Table into a DataTable is that you:
    1. Create a database connection
    2. Create a database command
    3. Create a database adapter
    4. Create a new DataTable
    5. Load the data from the adapter into the DataTable


    Here is a simplified example:
    Code:
    Dim table = New DataTable()
    Using connection = New MySqlConnection("my connection string")
        Using command = New MySqlCommand("SELECT * FROM MyTable", connection)
            Using adapter = New MySqlDataAdapter(command)
                connection.Open()
                adapter.Fill(table)
            End Using
        End Using
    End Using
    
    ' table now contains every record
    Is that an example of an ADO.net process?

    Both these lines are erroring

    Imports MySql.Data
    Imports MySql.Data.MySqlClient

    How to fix that, error has to do with namespace






    Option Strict Off
    Option Explicit On
    Imports System.Data


    Severity Code Description Project File Line Suppression State
    Warning BC40056 Namespace or type specified in the Imports 'MySql.Data.MySqlClient' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. sdlsconverted C:\vbnetJess1\WindowsApplication1\WindowsApplication1\frmOpener.vb 8 Active


    Imports MySql.Data
    Imports MySql.Data.MySqlClient

    Code:
    Option Strict Off
    Option Explicit On
    Imports System.Data
    
    Imports MySql.Data
    Imports MySql.Data.MySqlClient
    
    Friend Class frmOpener
    	Inherits System.Windows.Forms.Form
    	
        Private clsElastic As New clsElasticForms
    	'Private secret As Variant, MySQLPrev As Variant, MariaDBPrev As Variant
    	Private MySQLPrev, secret, MariaDBPrev As String
    	
    	Private A1, A2 As Short
    	Private provider1 As String
    	Private driver1 As String
    	Private host1 As String
    	Private dbname1 As String

  17. #17
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    Is that an example of an ADO.net process?

    Both these lines are erroring

    Imports MySql.Data
    Imports MySql.Data.MySqlClient

    How to fix that, error has to do with namespace






    Option Strict Off
    Option Explicit On
    Imports System.Data


    Severity Code Description Project File Line Suppression State
    Warning BC40056 Namespace or type specified in the Imports 'MySql.Data.MySqlClient' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. sdlsconverted C:\vbnetJess1\WindowsApplication1\WindowsApplication1\frmOpener.vb 8 Active


    Imports MySql.Data
    Imports MySql.Data.MySqlClient

    Code:
    Option Strict Off
    Option Explicit On
    Imports System.Data
    
    Imports MySql.Data
    Imports MySql.Data.MySqlClient
    
    Friend Class frmOpener
    	Inherits System.Windows.Forms.Form
    	
        Private clsElastic As New clsElasticForms
    	'Private secret As Variant, MySQLPrev As Variant, MariaDBPrev As Variant
    	Private MySQLPrev, secret, MariaDBPrev As String
    	
    	Private A1, A2 As Short
    	Private provider1 As String
    	Private driver1 As String
    	Private host1 As String
    	Private dbname1 As String
    You would need to add a reference to the MySql client dll, or install the MySql nuget package.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by PlausiblyDamp View Post
    You would need to add a reference to the MySql client dll, or install the MySql nuget package.
    Ok doing that reference to MySQL dll gets rid of the namespace error, but still con.open() fails

    Since I made some progress it is good. Will review the Mysql help page showing a vbnet connection example

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by Shaggy Hiker View Post
    I would also go with ADO.NET, but it might require significant changes. When I was working in VB6, I wasn't using ADO. I was using DAO, and I'm not sure how different those two are. I suspect that DAO may be closer to ADO than either is to ADO.NET, though.

    Database work in VB6 tended to follow the model of connecting to the DB and working with it in some way. In ADO.NET, you generally connect to the DB, suck the data into local memory, then close the connection. You then work with what you have in memory, and if necessary, then push changes back to the DB. It's a model that largely separates the DB from the program, with only temporary, relatively light, interactions.

    If you were using recordsets in ADO, then you'd probably be using a dataadapter or a datareader to pull data into a datatable in place of that. That could require quite different code for those areas, or a different design of the program in general. Exactly how much effort it would be is hard to say. It might be trivial, it might be extreme.

    I do things with a server like build ADO recordsets on the local machine including using getrows.
    I also do some temporary tables and insert into etc... on the server itself.
    I use movenext in some recordsets.
    I imagine a rewrite would not be a trivial thing.

    However things are working fine with MSSQL database server and my existing code in vs2022, so if I can get a conn to a MariaDB or MySQL to work, I think it would just work as is.

    Understand this is a database library program for small libraries, like where my wife works that I designed 25 yrs ago. It does not need any high capacity million record rows or any such thing. Right now it just works fine and has for a long time.

    But I was interested in adding unicode capacity for it to work with other languages, that is my primary goal. And vbnet I read works with unicode. I already converted mysql and mariadb to unicode and can using the windows console work with insertng unicode chars into the databases.
    Last edited by sdowney1; Apr 22nd, 2024 at 01:29 PM.

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    ok, here is the mysql vbnet example for ODBC
    it uses this namespace
    https://dev.mysql.com/doc/connector-...ng-net-vb.html

    Imports Microsoft.Data.Odbc , which has the same error as before with mysql

    What dll refence does it need for that?
    Is it this here Microsoft.Data.Odbc.dll


    MySQL's own code example for their site
    Code:
    ' @sample    : myvb.vb
    ' @purpose   : Demo sample for ODBC.NET using Connector/ODBC
    '
    
    '
    ' build command
    '
    ' vbc /target:exe
    '     /out:myvb.exe
    '     /r:Microsoft.Data.Odbc.dll
    '     /r:System.dll
    '     /r:System.Data.dll
    '
    
    Imports Microsoft.Data.Odbc
    Imports System
    
    Module myvb
      Sub Main()
        Try
    
          'Connector/ODBC 3.51 connection string
          Dim MyConString As String = "DRIVER={MySQL ODBC 3.51 Driver};" & _
          "SERVER=localhost;" & _
          "DATABASE=test;" & _
          "UID=venu;" & _
          "PASSWORD=venu;" & _
          "OPTION=3;"
    
          'Connection
          Dim MyConnection As New OdbcConnection(MyConString)
          MyConnection.Open()

  21. #21
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    ok, here is the mysql vbnet example for ODBC
    it uses this namespace
    https://dev.mysql.com/doc/connector-...ng-net-vb.html

    Imports Microsoft.Data.Odbc , which has the same error as before with mysql

    What dll refence does it need for that?
    Is it this here Microsoft.Data.Odbc.dll
    [/CODE]
    That looks like the correct one, just add it as a reference to the project and see if the error goes away.

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by PlausiblyDamp View Post
    That looks like the correct one, just add it as a reference to the project and see if the error goes away.
    I think I found it here
    https://www.nuget.org/packages/Micro...tibility/8.0.4

    has a strange extension. Extracted with 7ZIP

    seems to imply you install it like this? Is that from a command prompt and if so in what dir?
    Do you even need to extract it? I find this confusing.

    >dotnet add package Microsoft.Windows.Compatibility --version 8.0.4

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Totally lost here, I opened a terminal in VS2022 and entered what appeared on the website cli for the package, which made no sense to me either
    and it looks like it did nothing

    **********************************************************************
    ** Visual Studio 2022 Developer PowerShell v17.9.6
    ** Copyright (c) 2022 Microsoft Corporation
    **********************************************************************
    PS C:\vbnetJess1\WindowsApplication1> dotnet add package Microsoft.Windows.Compatibility --version 8.0.4

    Welcome to .NET 8.0!
    ---------------------
    SDK Version: 8.0.204

    Telemetry
    ---------
    The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

    Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

    ----------------
    Installed an ASP.NET Core HTTPS development certificate.
    To trust the certificate, run 'dotnet dev-certs https --trust'
    Learn about HTTPS: https://aka.ms/dotnet-https

    ----------------
    Write your first app: https://aka.ms/dotnet-hello-world
    Find out what's new: https://aka.ms/dotnet-whats-new
    Explore documentation: https://aka.ms/dotnet-docs
    Report issues and find source on GitHub: https://github.com/dotnet/core
    Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
    --------------------------------------------------------------------------------------
    Could not find any project in `C:\vbnetJess1\WindowsApplication1\`.
    PS C:\vbnetJess1\WindowsApplication1>

  24. #24
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    I think I found it here
    https://www.nuget.org/packages/Micro...tibility/8.0.4

    has a strange extension. Extracted with 7ZIP

    seems to imply you install it like this? Is that from a command prompt and if so in what dir?
    Do you even need to extract it? I find this confusing.

    >dotnet add package Microsoft.Windows.Compatibility --version 8.0.4
    There are a couple of important things you need to be aware of.

    Firstly there are really two "flavours" of dotnet. You have the older .Net Framework which started as version 1.0 and progressed through to Version 4.8 (currently 4.8.1, and what used to be known as .Net Core (versions 1.0 - 3.0) and is now just called .Net (versions 5.0 - 8.0).

    These two flavours behave differently and before you go any further you need to know which you are using, and why.

    The .Net Framework versions have been around longer and some consider them to be more stable, however short of security / stability fixes they are effectively no longer being developed. These versions are also Windows only.

    The newer .Net versions are under active development, with version 8.0 being released last November. These versions are cross platform (Windows, Mac, and Linux) although some features may only be available on certain platforms.

    If you are using the older framework versions then you can add a reference to System.Data.dll and that will include the System.Data.Odbc namespace and the relevant ODBC classes will be under there; you can do this by right clicking on your project and going to Add -> Reference. There is a good chance this reference has already been added and you won't need to do anything.

    If on the other hand you are using the newer .Net you would need to install support as a nuget package, you can do this by right clicking on your project and going to "Manage Nuget PAckages". Then you can search for System.Data.Odbc and install it from the UI. IIRC Microsoft.Windows.Compatibility never actually included ODBC support but I could be wrong.

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by PlausiblyDamp View Post
    There are a couple of important things you need to be aware of.

    Firstly there are really two "flavours" of dotnet. You have the older .Net Framework which started as version 1.0 and progressed through to Version 4.8 (currently 4.8.1, and what used to be known as .Net Core (versions 1.0 - 3.0) and is now just called .Net (versions 5.0 - 8.0).

    These two flavours behave differently and before you go any further you need to know which you are using, and why.

    The .Net Framework versions have been around longer and some consider them to be more stable, however short of security / stability fixes they are effectively no longer being developed. These versions are also Windows only.

    The newer .Net versions are under active development, with version 8.0 being released last November. These versions are cross platform (Windows, Mac, and Linux) although some features may only be available on certain platforms.

    If you are using the older framework versions then you can add a reference to System.Data.dll and that will include the System.Data.Odbc namespace and the relevant ODBC classes will be under there; you can do this by right clicking on your project and going to Add -> Reference. There is a good chance this reference has already been added and you won't need to do anything.

    If on the other hand you are using the newer .Net you would need to install support as a nuget package, you can do this by right clicking on your project and going to "Manage Nuget PAckages". Then you can search for System.Data.Odbc and install it from the UI. IIRC Microsoft.Windows.Compatibility never actually included ODBC support but I could be wrong.
    Ok, sounds good, thanks.
    I selected net version 4.8 when I imported program from vs2008 which was 3.5 and it ran.
    How would you select 8.0 as it did not appear in project properties? Highest was 4.8.
    Is that something I have to download and install .Net 8.0?

  26. #26
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    If you have vs2022 then you probably have .Net 8.0, however unlike upgrading framework versions it isn't as simple to move from framework to the new style projects.

    https://dotnet.microsoft.com/en-us/p...rade-assistant is a tool that can help with the upgrade to the latest certain though.

    It might be worth sticking on the existing framework for now though, and seeing if you can get it working using System.Data.Odbc before introducing other complexities.

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by PlausiblyDamp View Post
    If you have vs2022 then you probably have .Net 8.0, however unlike upgrading framework versions it isn't as simple to move from framework to the new style projects.

    https://dotnet.microsoft.com/en-us/p...rade-assistant is a tool that can help with the upgrade to the latest certain though.

    It might be worth sticking on the existing framework for now though, and seeing if you can get it working using System.Data.Odbc before introducing other complexities.
    Issue came up system.data.dll is already referenced as part of system.data in the references for the program
    Must need a different file dll?
    Attached Images Attached Images  

  28. #28
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    Issue came up system.data.dll is already referenced as part of system.data in the references for the program
    Must need a different file dll?
    That just means you already have a reference to the library and therefore don't need to add a second reference to the library.

    Just see if you can import the System.Data.Odbc namespaces and use the classes it contains.

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by PlausiblyDamp View Post
    That just means you already have a reference to the library and therefore don't need to add a second reference to the library.

    Just see if you can import the System.Data.Odbc namespaces and use the classes it contains.
    in the Nuget PM, I did run the command and it got package and installed it
    will see if anything has changed

    PM> NuGet\Install-Package System.Data.Odbc -Version 8.0.0

    Attempting to gather dependency information for package 'System.Data.Odbc.8.0.0' with respect to project 'sdlsconverted', targeting '.NETFramework,Version=v4.8'
    Gathering dependency information took 555 ms
    Attempting to resolve dependencies for package 'System.Data.Odbc.8.0.0' with DependencyBehavior 'Lowest'
    Resolving dependency information took 0 ms
    Resolving actions to install package 'System.Data.Odbc.8.0.0'
    Resolved actions to install package 'System.Data.Odbc.8.0.0'
    Retrieving package 'System.Data.Odbc 8.0.0' from 'nuget.org'.
    GET https://api.nuget.org/v3-flatcontain...bc.8.0.0.nupkg
    OK https://api.nuget.org/v3-flatcontain...bc.8.0.0.nupkg 20ms
    Installed System.Data.Odbc 8.0.0 from https://api.nuget.org/v3/index.json to C:\Users\sdown\.nuget\packages\system.data.odbc\8.0.0 with content hash c+GfnZt2/HyU+voKw2fctLZClcNjPZPWS+mnIhGvDknRMqL/fwWlREWPgA4csbp9ZkQIgB4qkufgdh/oh5Ubow==.
    Adding package 'System.Data.Odbc.8.0.0' to folder 'C:\vbnetJess1\WindowsApplication1\packages'
    Added package 'System.Data.Odbc.8.0.0' to folder 'C:\vbnetJess1\WindowsApplication1\packages'
    Added package 'System.Data.Odbc.8.0.0' to 'packages.config'
    Successfully installed 'System.Data.Odbc 8.0.0' to sdlsconverted
    Executing nuget actions took 3.81 sec
    Time Elapsed: 00:00:04.6970822
    PM>

  30. #30

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    well of course it did not help
    'Microsoft.Data.Odbc', if it is a file, does not exist on my entire drive system

  31. #31
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Back in post #24 I mentioned that for framework applications (such as 4.8) you only need to add a reference to the System.data.dll and that this is probably already referenced anyway.

    If that is the case there is absolutely no need to install the additional Nuget package.

    Have you tried just importing the namespace like I suggested, and then trying to use one of the odbc classes?

    If not, please just try what I suggested.

  32. #32
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    well of course it did not help
    'Microsoft.Data.Odbc', if it is a file, does not exist on my entire drive system
    That package would have installed system.data.odbc.dll, that is what you would have needed. Then again you are probably not going to need it if you are using framework 4.8 anyway.

    If the package did install then it works be registered with the project as part of the install and you wouldn't need to be looking for it anyway.

  33. #33

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by PlausiblyDamp View Post
    That just means you already have a reference to the library and therefore don't need to add a second reference to the library.

    Just see if you can import the System.Data.Odbc namespaces and use the classes it contains.
    Can't says it already exists
    Attached Images Attached Images  

  34. #34
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    That is trying to reference the dll, not import it. You need to use the Imports keyword at the top of your source file.

    You have already shown examples of importing namespaces.

  35. #35
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,801

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    Ok doing that reference to MySQL dll gets rid of the namespace error, but still con.open() fails

    Since I made some progress it is good. Will review the Mysql help page showing a vbnet connection example
    Did you copy/paste my example exactly or is con.Open exactly what you’re doing? The reason I ask is because I declared the connection object as “connection” and not “con”. So if you have it as con.Open then rename it to connection.Open. If you already have it as connection.Open, what error message are you getting?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  36. #36

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by PlausiblyDamp View Post
    That is trying to reference the dll, not import it. You need to use the Imports keyword at the top of your source file.

    You have already shown examples of importing namespaces.
    I just put in the last line, but still fails to open connection
    The Imports line however does not error

    Imports MySql.Data
    Imports MySql.Data.MySqlClient
    'Imports Microsoft.Data.Odbc
    Imports System.Data.Odbc

    Mysql web site shows to use Imports Microsoft.Data.Odbc though

    I did find a conversation where someone had to install a nuget package and it solved this, but he does not say which version he installed.
    What version do you think I should try?

    https://stackoverflow.com/questions/...l-using-vb-net

  37. #37

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by dday9 View Post
    Did you copy/paste my example exactly or is con.Open exactly what you’re doing? The reason I ask is because I declared the connection object as “connection” and not “con”. So if you have it as con.Open then rename it to connection.Open. If you already have it as connection.Open, what error message are you getting?
    I can simply try the mysql example on the mysql page I suppose.

    the connection string is this

    ?con1.connectionstring
    "Provider=MSDASQL.1;DRIVER={MariaDB ODBC 3.1 Driver};DATABASE=;SERVER=localhost;UID=root;PASSWORD=root;PORT=3308;OPTION=34;"


    the error is always the same

    {Microsoft.VisualBasic.ErrObject}
    Description: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
    Erl: 0
    HelpContext: 0
    HelpFile: ""
    LastDllError: 1008
    Number: -2147467259
    Source: "Microsoft OLE DB Provider for ODBC Drivers"



    Here is my code for testing the connection
    Code:
     Private Sub cmdLogin_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLogin.Click
    
    
         ' Provider=MSDASQL.1;Extended Properties="DRIVER={MySQL ODBC 3.51 Driver};DESC=;DB=mysql;SERVER=localhost;UID=root;PASSWORD=sdlssdls;PORT=3306;SOCKET=;OPTION=35;STMT=;"
    
         On Error GoTo errhandler
    
         'construct a connection string from listed text in the boxes
         'leave it here this will be overwriten??
         provider1 = "Provider=" & _Text1_0.Text & ";"
         driver1 = "DRIVER=" & _Text1_1.Text & ";"
         host1 = "SERVER=" & _Text1_2.Text & ";"
         dbname1 = "DATABASE=" & Combo1.Text & ";"
         user1 = "UID=" & _Text1_4.Text & ";"
         pass1 = "PASSWORD=" & _Text1_5.Text & ";"
         port1 = "PORT=" & _Text1_6.Text & ";"
         opt1 = "OPTION=" & _Text1_7.Text & ";"
    
         frmlogonConnectstring = provider1 & driver1 & dbname1 & host1 & user1 & pass1 & port1 & opt1
    
        Me.Cursor = Cursors.WaitCursor
    
         System.Windows.Forms.Application.DoEvents()
         'test the connection
         Dim Con1 As New ADODB.Connection
         Dim NoError As Boolean
         Con1.ConnectionString = frmlogonConnectstring
         Con1.Open()

  38. #38
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    I just put in the last line, but still fails to open connection
    The Imports line however does not error

    Imports MySql.Data
    Imports MySql.Data.MySqlClient
    'Imports Microsoft.Data.Odbc
    Imports System.Data.Odbc

    Mysql web site shows to use Imports Microsoft.Data.Odbc though

    I did find a conversation where someone had to install a nuget package and it solved this, but he does not say which version he installed.
    What version do you think I should try?

    https://stackoverflow.com/questions/...l-using-vb-net
    If you want to use odbc then you don't need to install any other packages. That link is talking about installing the .net MySql client.
    Don't bother with that unless you want to forget about odbc and use the native client. Personally I would go the native client route but so far you have expressed a desire to use odbc.

    Does it give any error when it fails to open?

    I wouldn't worry about the Microsoft.data.odbc thing, I suspect it was specific to a particular version of dotnet.

  39. #39

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2024
    Posts
    508

    Re: This code won't open database connection in vs2008, it does work in vb6

    ?err
    {Microsoft.VisualBasic.ErrObject}
    Description: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
    Erl: 0
    HelpContext: 0
    HelpFile: ""
    LastDllError: 1008
    Number: -2147467259
    Source: "Microsoft OLE DB Provider for ODBC Drivers"

    error is always the same
    I tried putting in the database name into the string, no good.
    dbname1 = "DATABASE=booksgood;"

    for laughs, I will copy the connection string and paste it into vb6 program and see if it works, it should as it is the same code.

  40. #40
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,544

    Re: This code won't open database connection in vs2008, it does work in vb6

    Quote Originally Posted by sdowney1 View Post
    ?err
    {Microsoft.VisualBasic.ErrObject}
    Description: "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
    Erl: 0
    HelpContext: 0
    HelpFile: ""
    LastDllError: 1008
    Number: -2147467259
    Source: "Microsoft OLE DB Provider for ODBC Drivers"

    error is always the same
    I tried putting in the database name into the string, no good.
    dbname1 = "DATABASE=booksgood;"

    for laughs, I will copy the connection string and paste it into vb6 program and see if it works, it should as it is the same code.
    Have you installed a MySql odbc driver?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width