mattn / go-adodb

Microsoft ActiveX Object DataBase driver for go that using exp/sql
http://mattn.kaoriya.net/
MIT License
142 stars 36 forks source link

Error while creating MDB file with provided example #57

Open pa0108 opened 2 years ago

pa0108 commented 2 years ago

I just tried with the sample code provided in mdb.go but getting empty error message. Any help? Below is the code to test.

package main

import ( "database/sql" "fmt" "os" _ "runtime/cgo" "time"

"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
_ "github.com/mattn/go-adodb"

)

var provider string

func createMdb(f string) error { unk, err := oleutil.CreateObject("ADOX.Catalog") if err != nil { fmt.Println(err) return err } defer unk.Release() cat, err := unk.QueryInterface(ole.IID_IDispatch) if err != nil { fmt.Println("2") return err } defer cat.Release() provider = "Microsoft.Jet.OLEDB.4.0" r, err := oleutil.CallMethod(cat, "Create", "Provider="+provider+";Data Source="+f+";") if err != nil { provider = "Microsoft.ACE.OLEDB.12.0" r, err = oleutil.CallMethod(cat, "Create", "Provider="+provider+";Data Source="+f+";") if err != nil { fmt.Println("3") return err } } r.Clear() return nil }

func main() { ole.CoInitialize(0) defer ole.CoUninitialize()

f := "./example.mdb"

os.Remove(f)

err := createMdb(f)
if err != nil {
    fmt.Println("create mdb", err)
    return
}

}