dcsimg
Results 1 to 6 of 6

Thread: Connection string for MySQL opening MySQL connection

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2015
    Posts
    24

    Connection string for MySQL opening MySQL connection

    I am new to MySQl and copied this code from somewhere. I have download MySQL and imported Mysql.data.mysqlclient

    I get this error

    "Unable to connect to any of the specified MySQL hosts"

    the code is as follows;

    Code:
     
    
    Sub CreatDB()
    
            Dim conn As MySqlConnection
            Dim strConn As String
            Dim cmd As MySqlCommand
    
            
            strConn = "Server=127.0.0.1;userid=root;Pwd=12345;Database=test;pooling=false;"
            
            conn = New MySqlConnection(strConn)
    
            cmd = New MySqlCommand("Create Database If Not exists Onteora", conn)
    
            conn.Open()
    
            cmd.ExecuteNonQuery()
            conn.ChangeDatabase("Onteora")
    
            Dim sbCmd As New System.Text.StringBuilder
    
            sbCmd.Append("Create Table If Not Exists Blog ")
            sbCmd.Append("(ID varchar(36) PRIMARY KEY, PostDate date, BlogText Text)")
    
            cmd = New MySqlCommand(sbCmd.ToString, conn)
            cmd.ExecuteNonQuery()
            conn.Close()
    
    
    
        End Sub

    what else do i need to do? thanks

    Richard

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,795

    Re: Connection string for MySQL opening MySQL connection

    first guess - the server isn't running.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    311

    Re: Connection string for MySQL opening MySQL connection

    You could also try Server=localhost as it appears that you are just trying to connect to a local database that resides on your computer. Also I assume you are using the MySQL Connector/Net driver (since you mention importing MySQLClient)... If so, then your connection string isn't correct. The proper usage is:
    Code:
    "Server=127.0.0.1;Uid=root;Pwd=12345;Database=test;pooling=false;"
    I'm also wondering what is your reasoning for turning off connection pooling? Unless you have a specific reason, you really should keep it on as this will make connections faster...

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2015
    Posts
    24

    Re: Connection string for MySQL opening MySQL connection

    I have been using sql lite for a while now and its very simple to create DB. So what does it mean that the server isnt running?

    I am just trying to create a DB on my PC, to be honest, not on any network

    I tried Server=localhost also

    Please not I dont have a database already I am connecting too I am trying to create one

    I dont really know what pooling is so i will trying changing to true

    If it helps at all here is the error in detail

    MySql.Data.MySqlClient.MySqlException was unhandled
    ErrorCode=-2147467259
    HResult=-2147467259
    Message=Unable to connect to any of the specified MySQL hosts.
    Number=1042
    Source=MySql.Data
    StackTrace:
    at MySql.Data.MySqlClient.NativeDriver.Open()
    at MySql.Data.MySqlClient.Driver.Open()
    at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
    at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
    at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
    at MySql.Data.MySqlClient.MySqlPool.GetConnection()
    at MySql.Data.MySqlClient.MySqlConnection.Open()
    at rpMySQL.Form1.CreatDB() in C:\Users\Julie\documents\visual studio 2010\Projects\rpMySQL\rpMySQL\Form1.vb:line 39
    at rpMySQL.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\Julie\documents\visual studio 2010\Projects\rpMySQL\rpMySQL\Form1.vb:line 61
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    at System.Windows.Forms.Application.Run(ApplicationContext context)
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
    at rpMySQL.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
    InnerException:

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,795

    Re: Connection string for MySQL opening MySQL connection

    IT means the service isn't running. Just like Word isn't running until you open it... Depending on how you installed it, there should be a utility somewhere where you can start/stop/restart the service. But what utility have can vary depending on how it was installed.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2015
    Posts
    24

    Re: Connection string for MySQL opening MySQL connection

    i may have just realised something. Am i right in saying i need to install mysql server as it then installs a service? ? The tutorial i was reading made no mention of this and just installed the connector. So i did install the service and the service had started. However on running my code i still got same error

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width