当前位置:网站首页>对pyqt5和SQL Server数据库进行连接
对pyqt5和SQL Server数据库进行连接
2022-06-09 05:18:00 【CSDN问答】
问题遇到的现象和发生背景
在进行pyqt5和SQL Server进行连接时,输入参考网上的相关代码后,但无法进行连接
问题相关代码,请勿粘贴截图
#导入QtSql模块
from PyQt5.QtSql import QSqlDatabase, QSqlQuery
#创建数据库连接并打开(未指定数据库名,创建默认连接)
db = QSqlDatabase.addDatabase("QODBC")
db.setDatabaseName("Driver={Sql Server};Server=LAPTOP-GKV1SQBI;Database=WDDB;Uid=sa;Pwd=123456")
db.open()
ok = db.open()
print(ok)
"测试是否成功,记得关闭连接"
if ok:
db.close()
print("Database closed")
运行结果及报错内容
如果直接运行,则不报错,用if语句对其进行判断,则显示false。
我的解答思路和尝试过的方法
参考网上代码后,已根据本机运行环境对服务器名,SQL Server的数据库名,用户名,以及密码都进行了修改。通过这些信息,对python和SQL Server已成功地进行了连接,以确保这些信息无误
我想要达到的结果
成功进行连接
边栏推荐
- AI video cloud: a good wife in the era of we media
- FPGA based TDC Research Report
- 2022年茶艺师(中级)考试题模拟考试题库及模拟考试
- validate-npm-package-name
- Ribbon vs feign - with simple examples
- ^25 processes and threads
- Cuijian hasn't changed. BAIC Jihu should make a change
- [django learning notes - 12]: database operation
- [it] Foxit PDF retention tool selection
- A few minutes to understand the Flink waterline
猜你喜欢

内网渗透 - 哈希传递攻击

Apache devlake code base guide

Transformer裏面的緩存機制

Requests segmented downloading of files and multi-threaded downloading

The difference between traditional method and lean method

ps如何给图像加边框

Sonarlint代码规范改造实践及一些想法

MRNA factory| quantitative detection of LNP encapsulated RNA content by ribogreen

好榛子出辽阳!

wps ppt图片如何一张一张出来
随机推荐
Design owlook network novel recommendation system
2022年危险化学品经营单位主要负责人操作证考试题库及在线模拟考试
STM32 FreeRTOS task Basics
材料之kube-dns.yaml
Leetcode 929.独特的电子邮件地址
Source code analysis of reentrantreadwritelock of AQS
Summary of Android Engineer interview experience with 5 years' work experience, summary of real interview questions of Ali + Tencent + byte jump
由id获取name调用示例(腾讯IM)
【IT】福昕pdf保持工具選擇
Alibaba cloud AI training camp MySQL foundation 1:
^26浏览器的内核
Recommend this UI automation testing framework and write use cases as colloquially as possible
Windows10 installs both MySQL 5 and MySQL 8
Transformer裏面的緩存機制
Failed to crawl HTML into MySQL insert
Data Summit 2022 大会资料分享(共23个)
Thinking of reading
爬取html入mysql插入失败
模式识别大作业——PCA&Fisher&KNN&Kmeans
Quickly detect high-risk vulnerabilities of common middleware and components in penetration testing