Open pa0108 opened 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 }
}
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"
)
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()
}