相关文章推荐

Hey, while trying to connect the SQL server from python I'm getting an operational error.

import pyodbc

conn = pyodbc.connect("DRIVER={SQL Server Native Client 11.0};"
"SERVER=g1_mssql0;PORT=23001;"
"DATABASE=***;"
"UID=sa;""PWD=********")

OperationalError: ('08001', '[08001] [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][SQL Server Native Client 11.0]Login timeout expired (0); [08001] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0); [08001] [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (53)')

can you please help me out how to fix this

Hi @Pentyala, Avinash C ,

We have not received a response from you. Did the reply could help you? If the response helped, do " Accept Answer ". If it doesn't work, please let us know the progress. By doing so, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.

Best regards,

Seeya

Hi @Pentyala, Avinash C ,

Welcome to Microsoft Q&A!
From your error message, I've put together a few areas to help you do troubleshooting.

  • Enter wrong server details by mistake. Make sure to enter correct SQL Server instance name while making database connection.
  • Try to connect using ip address and port number instead of putting server name in connection string.
  • SQL Server Instance is not accessible due to firewall or any reason. Check firewall details. Your port 23001 and UDP port (1434) of SQL Server browser should be enabled. These ports might be blocked.
  • SQL Server service is not running on SQL Server. You can try to start or restart SQL Server services
  • Make sure to enable TCP/IP and Named Pipes, which you can check from SQL Server Configuration Manager.
  • Remote connection must be enabled to connect to databases remotely. Right click on SQL Server instance name in SSMS and choose Properties. You will get Server properties window. Click on Connections from left side pane and tick the check box on Allow remote connections to this server option from right side pane.
  • SQL browser service should not be stopped if your security policy allows it.
    Hope this could give you some help.
  • Best regards,
    Seeya

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Hello, thanks for the reply. After restarting the SQL server it got connected. But after some time I lost the connection and my SQL server is running.
    I'm not sure what the issue is.
    kindly check the attached screenshots

    Hi @Pentyala, Avinash C ,

    You can follow my previous reply to troubleshoot step by step, I also provide the corresponding steps that should be tried.

    Best regards,
    Seeya

    "SERVER=g1_mssql0; PORT=23001 ;"

    Is your SQL Server really setup with IP port 23001? That's unusally, default is 1433.

    "DATABASE=;"

    An empty database name? Huh? Where should the connect go thru?

    Hello, it's not an empty database. I gave db_name at the time of execution while uploading i just removed it.

    it's a docker file. all the databases are loaded in that.

    I'm confused because it's standard practice to obfuscate or remove things like database name, server name, IP address, login details..

    why would you think he is using an empty field? not only that, but it's clear from his posts that this setup was working fine, and began having the login error afterwards. Furthermore, if the database name was really empty, the error he received would not be the one shown in his posts, it would be the database not found error (i forget what code that is).

    it seems as if you weren't really interested in helping the OP.

    #To execute queries, the “cursor()” object of the connection object is used. The following script stores the cursor object in the “cursor” variable: cursor = conn.cursor() select_record = '''select convert(date,create_t) as create_t,count(ordernumber) as ordercount from yourtable where create_t>='2023-03-01' group by convert(date,create_t) ''' sql_query =pd.read_sql_query(select_record,conn) cursor.execute(select_record) df = pd.DataFrame(sql_query, columns = ['create_t', 'ordercount']) print (df)

    Attachment of My SQL Server Connection>>>

    what should i write code on my jupyter Notebook to connect my sql there

    My database name is : SQL_Databse

    bellow I tried the step :

    #installing Librarry for first time for SQL

    !pip install ipython-sql

    import pyodbc

    cnxn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};Server=VIVEK\SQLEXPRESS01;Database=SQL_Databse;User ID=?;Password=?')

    Help me with the correct code to connect my SQL

    Note : ? mark is used to denote the things to

     
    推荐文章