// Pipe - A small and beautiful blogging platform written in golang. // Copyright (C) 2017-2018, b3log.org // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . package service import ( "fmt" "github.com/astaxie/beego" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/mssql" // mssql _ "github.com/jinzhu/gorm/dialects/mysql" // mysql ) var dataBase2 *gorm.DB var ( dbName2 = "local" user2 = beego.AppConfig.DefaultString(dbName2+"::user", "KingMed") password2 = beego.AppConfig.DefaultString(dbName2+"::password", "KingMed") host2 = beego.AppConfig.DefaultString(dbName2+"::host", "localhost") port2 = beego.AppConfig.DefaultString(dbName2+"::port", "1433") dbname2 = beego.AppConfig.DefaultString(dbName2+"::dbname", "KMDB") ) func ConnectMSDB2() { connectionString := fmt.Sprintf("server=%s;user id=%s;password=%s;port=%s;database=%s;encrypt=disable", host2, user2, password2, port2, dbname2) fmt.Println(connectionString) db, err := gorm.Open("mssql", connectionString) if err != nil { fmt.Println("failed to connect database") fmt.Println(err) } db.LogMode(true) db.CommonDB() dataBase = db }