# Pymssql - connection - database name

**URL:** <https://discuss.python.org/t/pymssql-connection-database-name/2605>\
**Category:** Python Help\
**Created:** [November 6, 2019, 8:07am UTC](https://discuss.python.org/t/pymssql-connection-database-name/2605 "2019-11-06T08:07:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rasheeda](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rasheeda](https://discuss.python.org/u/rasheeda)\
**Post date:** [November 6, 2019, 8:07am UTC](https://discuss.python.org/t/pymssql-connection-database-name/2605/1 "2019-11-06T08:07:48Z")

</div>

Hi,

I am trying to connect to a MS sql database using pymssql, following is my line of code

import pymssql as ms

try:

```
conn = ms.connect(host='xyz\SQLEXPRESS',user='abc', password='abc', database='Testdb')

```

except ms.DatabaseError as e:  
print('database error ', e.args)

and am always getting following error.  
database error ((20009, b’DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (xyz\SQLEXPRESS)\n’),)

Notice that in above error message \ is appended, though i have given single slash.

Please advice solution.

---

<div class="post-metadata">

**Author:** ![rasheeda](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rasheeda](https://discuss.python.org/u/rasheeda)\
**Post date:** [November 6, 2019, 8:09am UTC](https://discuss.python.org/t/pymssql-connection-database-name/2605/2 "2019-11-06T08:09:01Z")

</div>

actual error message was database error ((20009, b’DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (xyz\\SQLEXPRESS)\n’),)

double \\ which got striped when submitting topic from the browser

---

<div class="post-metadata">

**Author:** ![uranusjr](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/uranusjr/32/103_2.png) [@uranusjr](https://discuss.python.org/u/uranusjr)\
**Post date:** [November 7, 2019, 7:35am UTC](https://discuss.python.org/t/pymssql-connection-database-name/2605/3 "2019-11-07T07:35:27Z")

</div>

The error message is quite literal, it means it cannot find to the server you specified. Possible causes are:

- You specified the wrong host
- The database server is not up
- The host machine blocked the port used by SQL server for connection
- The client’s OS blocked connection to host

---

<div class="post-metadata">

**Author:** ![rasheeda](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rasheeda](https://discuss.python.org/u/rasheeda)\
**Post date:** [November 13, 2019, 11:23am UTC](https://discuss.python.org/t/pymssql-connection-database-name/2605/4 "2019-11-13T11:23:13Z")

</div>

The server is very much there and operational, i make frequent connection with same connection string in C#, [Asp.net](http://Asp.net) every day.  
My instance name is sqlexpress hence i have to append with server name as xyz\sqlexpress.

I think you missed something from my message. there is double backward slash in the string being displayed for the error when though i typed single backward slash.  
I faced same issue in Node-Red as well

---

<div class="post-metadata">

**Author:** ![aeros](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/aeros/32/4140_2.png) [@aeros](https://discuss.python.org/u/aeros)\
**Post date:** [November 27, 2019, 2:51am UTC](https://discuss.python.org/t/pymssql-connection-database-name/2605/5 "2019-11-27T02:51:17Z")

</div>

> [@rasheeda](#):
>
> try:
> 
> ```auto
> conn = ms.connect(host='xyz\SQLEXPRESS',user='abc', password='abc', database='Testdb')
> 
> ```
> 
> except ms.DatabaseError as e:  
> print('database error ', e.args)
> 
> and am always getting following error.  
> database error ((20009, b’DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (xyz\SQLEXPRESS)\n’),)
> 
> Notice that in above error message \ is appended, though i have given single slash.

To avoid the `\` issue, you could pass the argument for _host_ as a raw string:

```py
conn = ms.connect(host=r'xyz\SQLEXPRESS',user='abc', password='abc', database='Testdb')

```

or escape the backslash:

```py
conn = ms.connect(host='xyz\\SQLEXPRESS',user='abc', password='abc', database='Testdb')

```

However, in general I would recommend using (or at least trying) `/` instead of `\`. I’m not 100% certain in the case of the `pymyssql` `connect()` function, but they’re typically treated the same for the purpose of defining paths.
