admin管理员组

文章数量:1336380

I do

pymssql.connect(server=self.host, user=self.username, password=self.password, port=self.port, database=database_name)

then

with conn.cursor() as cursor:

cursor.execute(sql, args)

cursor.fetchall()

then

self.interface.execute("SELECT DB_NAME()")

And I see 'master'

Then do connection.close()

And again the same loop but with 'products' as DB name. But when I do SELECT DB_NAME() again - I see 'master' again instead of 'products'

Why?

Also I've enabled tds debugs and I see next

  1 3470 pulse: size_bytes
  2 
  3 3711 net.c:318:Connecting to 127.0.0.1 port 62117
  4 
  5 4224 dblib.c:1377:dbcmd(0x107775f0, SELECT DB_NAME()) 
  6 
  7 4317                 select CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)*8192                                                      
  8 
  9 4446 dblib.c:1491:dbclose(0x10776fd0)                                                                                              
 10 4447 dblib.c:236:dblib_del_connection(0x7bbd9d3cba20, 0x1076a2d0)                                                                  
 11 4448 query.c:3804:tds_disconnect()                                                                                                 
 12 
 13 
 14 new connect after 
 15 ---
 16 4525 net.c:318:Connecting to 127.0.0.1 port 62117
 17 
 18 4779 dbutil.c:76:msgno 5701: "Changed database context to 'products'."                                                             
 19 
 20 4921 dblib.c:1450:dbuse(0x1083c370, products)
 21 4922 dblib.c:1377:dbcmd(0x1083c370, use [products]) 
 22 
 23 4956 dblib.c:300:db_env_chg(0x1042b860, 1, products, products)                                                                     
 24 4963 dbutil.c:76:msgno 5701: "Changed database context to 'products'."                                                             
 25 
 26 5039 dblib.c:1377:dbcmd(0x107775f0, SELECT DB_NAME())                                                                              
 27 
 28 
 29 5058 0010 00 e7 00 01 09 04 d0 00-34 00 d1 0c 00 6d 00 61 |........ 4....m.a|                                                      
 30 5059 0020 00 73 00 74 00 65 00 72-00 fd 10 00 c1 00 01 00 |.s.t.e.r ........|  

So context changed but I still somehow get 'master' as context. Why?

本文标签: pythonpymssql can connect to 39master39 but can39t connect to another database afterStack Overflow