简体   繁体   English

使用PyODBC和SQL Express Server 2008进行备份时,我在做什么?

[英]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. 有关详细信息,我正在运行python和PyODBC的最新版本,并尝试远程实例化SQL上的备份。 I don't know much about SQL. 我对SQL不太了解。 I've tried googling the issue and have tried a few tricks below including using .nextset() and trying different encodings just in case. 我已经尝试过搜索该问题,并尝试过以下一些技巧,包括使用.nextset()并尝试其他编码,以防万一。 I see a large surge on the local network of the PC with the SQL server but it very quickly tapers to nothing. 我看到带有SQL Server的PC的本地网络出现了大幅增长,但很快就没有了任何变化。 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. 我似乎也无法运行存储过程,因为尽管存在该存储过程,但似乎无法找到它,并且能够使用SSMS或远程PC上的SSMS在本地计算机上运行它。 Also I've given complete access to the remote account accessing the sql server as far as I know 据我所知,我还授予了访问SQL Server的远程帐户的完全访问权限

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. 如果您需要使用PyODBC进行备份的示例,则此代码非常有用。 I unfortunately was looking in the George folder instead of Fred. 不幸的是,我正在查找George文件夹而不是Fred。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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