Get Database size

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
b.szabo
Posts: 14
Joined: Wed 04 Jul 2007 05:50

Get Database size

Post by b.szabo » Tue 04 Mar 2008 12:19

Hi,

I want to get the size, of the selected Database in bytes. Could you help me out with some vb code.

Thanks,
Barnabás

Alexey.mdr
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Post by Alexey.mdr » Tue 04 Mar 2008 15:19

Here's the code.
Hope you will easily get the idea.

Code: Select all

Imports CoreLab.Data
Imports CoreLab.MySql
Module Module1
    Sub Main()
        Dim mySelectQuery As String
        mySelectQuery = "show table status"

        Dim myConnection As New MySqlConnection("user id=root;password=root;host=localhost;database=test;")
        Dim myCommand As New MySqlCommand(mySelectQuery, myConnection)

        Dim totalSpace As Int32
        totalSpace = 0

        myConnection.Open()
        Dim myReader As MySqlDataReader
        myReader = myCommand.ExecuteReader()

        While (myReader.Read())
            Console.WriteLine(myReader.GetInt32(6) & "," & myReader.GetInt32(6))
            totalSpace += myReader.GetInt32(6) + myReader.GetInt32(6)
        End While

        myReader.Close()
        myConnection.Close()
        Console.WriteLine(totalSpace)
        Console.Read()

    End Sub
End Module


b.szabo
Posts: 14
Joined: Wed 04 Jul 2007 05:50

Post by b.szabo » Thu 06 Mar 2008 02:44

Thanks it worked perfect,

Barnabás

Alexey.mdr
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Post by Alexey.mdr » Thu 06 Mar 2008 06:31

You are welcome!
Hope it was quite clear that I had added data size column and index size column.
So you get the total database size.
Feel free to contact us if you have any further questions about MyDirect .NET.

Post Reply