PCM_Report/SQL_SERVER_快速修复指南.txt

96 lines
3.2 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

================================================================================
SQL Server 打包问题 - 快速修复指南
================================================================================
问题打包后程序能启动但SQL Server访问不了
================================================================================
快速修复步骤
================================================================================
1. 重新打包(使用修复脚本)
powershell -ExecutionPolicy Bypass -File .\rebuild_with_sqlserver_fix.ps1
2. 验证打包结果
cd .\dist\docx_creator
dir *.dll | Select-Object Name
dir *.pyd | Select-Object Name
应该看到:
- sybdb.dll 或 libtds.dll
- _mssql.pyd
- pyodbc.pyd
3. 运行诊断工具
Copy-Item .\test_sqlserver_in_exe.py .\dist\docx_creator\
cd .\dist\docx_creator
python test_sqlserver_in_exe.py
4. 测试主程序
.\dist\docx_creator\docx_creator.exe
================================================================================
已实施的修复
================================================================================
✅ 修改了 docx_creator_fixed.spec
- 自动查找并打包pymssql的DLL和PYD文件
- 自动查找并打包pyodbc的PYD文件
- 添加必要的隐藏导入_mssql, decimal, uuid
- 添加运行时hook
✅ 创建了 hook-pymssql.py
- 确保DLL搜索路径正确
✅ 创建了诊断工具
- test_sqlserver_in_exe.py
✅ 创建了一键打包脚本
- rebuild_with_sqlserver_fix.ps1
================================================================================
如果仍然无法连接
================================================================================
情况1pymssql导入失败
→ 检查 dist\docx_creator\ 中是否有 sybdb.dll
→ 运行诊断工具查看详细错误
情况2pyodbc连接失败
→ 在目标机器上安装 Microsoft ODBC Driver for SQL Server
→ 下载地址https://docs.microsoft.com/en-us/sql/connect/odbc/
情况3两者都失败
→ 运行诊断工具获取详细错误信息
→ 检查SQL Server配置防火墙、端口等
================================================================================
推荐配置
================================================================================
优先使用 pymssql自带驱动易于打包
备用方案 pyodbc需要系统ODBC驱动
代码示例:
try:
import pymssql
conn = pymssql.connect(server, database, user, password)
except:
import pyodbc
conn = pyodbc.connect(connection_string)
================================================================================
相关文档
================================================================================
详细说明SQL_SERVER_打包解决方案.md
修复总结SQL_SERVER_打包问题修复总结.md
诊断工具test_sqlserver_in_exe.py
打包脚本rebuild_with_sqlserver_fix.ps1
================================================================================