Skip to content

[appengine-cloudsql] driver: bad connection #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mkvirseeker opened this issue Jan 5, 2015 · 9 comments
Closed

[appengine-cloudsql] driver: bad connection #299

mkvirseeker opened this issue Jan 5, 2015 · 9 comments

Comments

@mkvirseeker
Copy link

I'm a beginner about google appengine and golang.
I've tried appengine-go to access cloud sql with this driver but meet the following error:
driver: bad connection

Can anyone give me some suggestions please?

This is a part of the codes:

import (
    "database/sql"
    "fmt"
    _ "github.com/go-sql-driver/mysql"
    "net/http"
)

func Handler(w http.ResponseWriter, r *http.Request) {
    db, dbErr := sql.Open("mysql", "myUser@cloudsql(myProject:myInstance)/myDB")
    if dbErr != nil {
        fmt.Fprintf(w, "open err\n")
        http.Error(w, dbErr.Error(), 500)
        return
    }

    defer db.Close()
    pingErr := db.Ping()
    if pingErr != nil {
        fmt.Fprintf(w, "ping err\n")
        http.Error(w, pingErr.Error(), 500)
        return
    }

    rows, rowErr := db.Query("SELECT iduserInfo, userName FROM userInfo")
    if rowErr != nil {
        fmt.Fprintf(w, "Query err\n")
        http.Error(w, rowErr.Error(), 500)
        return
    }

    for rows.Next() {
        var (
            userID   int
            userName string
        )
        if err := rows.Scan(&userID, &userName); err != nil {
            http.Error(w, err.Error(), 500)
        }
        fmt.Fprintf(w, "%d is %s\n", userID, userName)
    }

    if err := rows.Err(); err != nil {
        http.Error(w, err.Error(), 500)
    }
}
@derekperkins
Copy link

This DSN works great for us. I don't know if you took out your password just for GitHub, but it should be in the string.
username:password@cloudsql(appID:CloudSQLInstance)/databasename?parseTime=true&loc=UTC

@goors
Copy link

goors commented Jun 20, 2015

I am getting error:

Runtime Panic
dial cloudsql: unknown network cloudsql 

can you help?

@derekperkins
Copy link

What's your connection string and where are you running it from?

@mkvirseeker
Copy link
Author

Sorry I had a wrong setting and I fixed eventually.
But still, thank you for reply.

Derek Perkins [email protected] 於 2015年6月20日週六 下午11:10 寫道:

What's your connection string and where are you running it from?


Reply to this email directly or view it on GitHub
#299 (comment)
.

@verdverm
Copy link

verdverm commented Sep 6, 2015

@goors @derekperkins

fyi, go get gets the most recent tag which still lacks the cloudsql support

instead, you have to manually clone this repository into your gopath and then all is groovy

same resolution here: http://stackoverflow.com/questions/21368363/how-to-connect-to-google-cloud-sql-with-go-sql-driver-mysql-on-app-engine

@billHaggerty
Copy link

is this still true?

fyi, go get gets the most recent tag which still lacks the cloudsql support

@bagatelli
Copy link

Is this still the case? I can't get the driver to work in AppEngine environment.

@pjebs
Copy link

pjebs commented Oct 12, 2016

No it works perfectly for me - but I use first gen. Are you using a first gen or second gen cloud sql database? #484

@evoshawkins
Copy link

@mkvirseeker

Sorry I had a wrong setting and I fixed eventually.

Possibly I have a wrong setting also. Could you share what setting you fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants