简体   繁体   中英

What's am I doing wrong with this backup using PyODBC and SQL Express Server 2008

For details I'm running a very recent version of python and PyODBC and am trying to remotely instantiate a backup on SQL. I don't know much about SQL. I've tried googling the issue and have tried a few tricks below including using .nextset() and trying different encodings just in case. I see a large surge on the local network of the PC with the SQL server but it very quickly tapers to nothing. I also can't seem to run a stored procedure as it will never seem to find it despite it existing and being able to run from my local machine using SSMS or the SSMS on the remote PC. Also I've given complete access to the remote account accessing the sql server as far as I know

Here is the relevant function:

    def back_up_and_restore(self):

        if self.Arbin not in [3, 4]:
            self.errorString = "Not remote server!"
            return self.errorString

        self.cnxn = pyodbc.connect(self.connectionString(self.db[0]))
        self.cursor = self.cnxn.cursor()
        self.cnxn.autocommit = True
        if self.Arbin == 3:
            folder = "Fred"
        else:
            folder = "George"


         query = r"BACKUP DATABASE [%s] TO  DISK = N'\\10.130.130.5\TestLab\DATA\%s\ArbinMasterData.bak' WITH NOFORMAT, INIT,  NAME = N'ArbinMasterData-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10" % ("ArbinMasterData", folder)
        #query = "{CALL BackUp%s2}" % folder
        query.encode(encoding='UTF-8')
        print(query)
        self.cursor.execute(query)
        time.sleep(2)
        while self.cursor.nextset():
            pass
        self.cnxn.close

When I run the function it just dies quickly and doesn't say anything. If I try running a stored procedure it says that the stored procedure doesn't exist. Any help would be great.

This code is working great if you need an example of PyODBC making a backup. I unfortunately was looking in the George folder instead of Fred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM