[python]pymssql去连接database由于名字含特殊字符总是失败,有什么解决办法没有

python資深小白 2014-11-25 02:17:39
如题。。。
database名字为testdb2.8,最后传进去connect的名字显示为testdb2,一直连接失败,
有没有人碰到同样的问题,怎么解决的???

conn = pymssql.connect(host='192.168.1.10', user='sa', password='testtest', database='testdb2.8')
...全文
251 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
python資深小白 2014-11-26
  • 打赏
  • 举报
回复
加引号:database='"testdb2.8"' 这个是正解 多谢大神。。。
引用 2 楼 panghuhu250 的回复:
没用过mssql。 查看pymssql的源码,追本朔源,最后落到freeTDS的select_db函数,他的文档说:
引用
RETCODE dbuse ( DBPROCESS * dbproc, const char * name ) Change current database. Analagous to the unix command cd, dbuse() makes name the default database. Waits for an answer from the server. Parameters: dbproc contains all information needed by db-lib to manage communications with the server. name database to use. Return values: SUCCEED query was processed without errors. FAIL query was not processed Todo: name should be quoted. See also: dbchange(), dbname().
不知道怎样“quote"数据库名。但可以试试: 加引号:database='"testdb2.8"' 加斜杠:database='testdb2\.8'
panghuhu250 2014-11-25
  • 打赏
  • 举报
回复
没用过mssql。 查看pymssql的源码,追本朔源,最后落到freeTDS的select_db函数,他的文档说:
引用
RETCODE dbuse ( DBPROCESS * dbproc, const char * name ) Change current database. Analagous to the unix command cd, dbuse() makes name the default database. Waits for an answer from the server. Parameters: dbproc contains all information needed by db-lib to manage communications with the server. name database to use. Return values: SUCCEED query was processed without errors. FAIL query was not processed Todo: name should be quoted. See also: dbchange(), dbname().
不知道怎样“quote"数据库名。但可以试试: 加引号:database='"testdb2.8"' 加斜杠:database='testdb2\.8'
The_Third_Wave 2014-11-25
  • 打赏
  • 举报
回复
两边加上、、试下?

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧