Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MACOS 系统使用 #1336

Closed
TzyTman opened this issue Mar 22, 2024 · 4 comments
Closed

MACOS 系统使用 #1336

TzyTman opened this issue Mar 22, 2024 · 4 comments

Comments

@TzyTman
Copy link

TzyTman commented Mar 22, 2024

import pyodbc

class SqlTest():
def init(self):
# 连接数据库
server = 'localhost'
database = 'SQL'
username = 'SA'
password = 'SQLsqlserver1234'
port = '1433'

    # 使用ODBC驱动连接SQL Server
    conn_str = f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server},{port};DATABASE={database};UID={username};PWD={password}'
    self.conn = pyodbc.connect(conn_str)

    # 创建游标对象
    self.cursor = self.conn.cursor()

def execute_query(self):
    # 执行查询
    self.cursor.execute('SELECT * FROM dbo.Customers')

    # 获取查询结果
    rows = self.cursor.fetchall()
    for row in rows:
        print(row)

def close_connection(self):
    # 关闭连接
    self.conn.close()

def main():
print("进入主应用程序")
sql_test = SqlTest()
sql_test.execute_query()
sql_test.close_connection()

if name == "main":
main()
报错:
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)")

@v-chojas
Copy link
Contributor

Check that the DM can find the driver, and that its dependencies are also available. You've given next to no information about your environment but if you're using macOS then run otool -L on the driver library to check its dependencies.

Also, this is an English project.

@TzyTman
Copy link
Author

TzyTman commented Mar 22, 2024 via email

@v-chojas
Copy link
Contributor

You can, but it won't help much if no one understands what you're trying to say.

@TzyTman
Copy link
Author

TzyTman commented Mar 23, 2024 via email

Repository owner locked and limited conversation to collaborators Mar 25, 2024
@gordthompson gordthompson converted this issue into discussion #1337 Mar 25, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants