Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
connection string issue
#1
Hi I am new to programming
Have be using python and trying things out.
Now trying to connect to my mssql 2016 database

The issue is he use of the \ character in the server name

Server=DesktopBne\sqlexpress

The other issue is the use of ! in the password
Password=sql4python!123!

Tried using the r option at front of string and various " and ' to get the character as not a line continuation

What is the syntax to get the character as the \ ?

Racone
Reply
#2
racone Wrote:The issue is he use of the \ character in the server name
Can you post the actual python code that you tried, so that we can see what the issue actually is?
Reply
#3
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=DESKTOP-BNIP8AB\\SQLEXPRESS;'
'Database=TestDemoe;'
'Trusted_Connection=yes;')

>>> conn = pyodbc.connect("Driver={SQL Server};"
"Server=DESKTOP-BNIP8AB\\SQLEXPRESS;"
"Database=Jiwa2010;"
"Trusted_Connection=yes;")
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
conn = pyodbc.connect("Driver={SQL Server};"
pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "Jiwa2010" requested by the login. The login failed. (4060) (SQLDriverConnect); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "Jiwa2010" requested by the login. The login failed. (4060)')
>>>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Virtual Env changing mysql connection string in python Fredesetes 0 323 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  pysftp connection issue geil007 0 2,721 May-18-2022, 08:40 AM
Last Post: geil007
  Last caracter of a string truncated issue when working from the end of the string Teknohead23 3 1,560 Oct-03-2021, 01:08 PM
Last Post: snippsat
  Serial connection connection issue Joni_Engr 15 7,829 Aug-30-2021, 04:46 PM
Last Post: deanhystad
  Weird SQLAchemy connection string error pawpaw 0 1,493 Jun-28-2020, 10:11 AM
Last Post: pawpaw
  Python C API - Issue with string as arugments JRHeisey 2 2,746 Nov-30-2019, 04:53 AM
Last Post: casevh
  List/String seperation issue YoungGrassHopper 13 5,356 Sep-20-2019, 11:57 AM
Last Post: perfringo
  Connection issue metro17 0 3,124 Aug-23-2019, 07:32 PM
Last Post: metro17
  Mixed string,Integer input variable issue maderdash 2 2,712 Nov-06-2018, 09:46 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020