Форум сайта python.su
Я смотрю соединение происходит по TCP. Насколько помню, из коробки оно выключено, посмотрите в настройках сервера. Кроме того, не знаю работает ли win аутентификация при работе через TCP.
Офлайн
Разбираю похожие варианты.
Пусть будет ответом. вдруг пригодится!
from sqlalchemy import create_engine, MetaData, Table from sqlalchemy.orm import mapper, sessionmaker from sqlalchemy.engine import URL class Bookmarks(object): pass def loadSessionLocalNGuidesSQLNew(): connection_string = r"""DRIVER={SQL Server Native Client 11.0}; SERVER=(localdb)\v11.0; DATABASE=C:\Какойто путь к базе\NGuidesSQLNew.mdf; UID=;PWD=""" connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": connection_string}) engine = create_engine(connection_url) metadata = MetaData(engine) ntypes = Table('NTypes', metadata, autoload=True) # Таблица NTypes mapper(Bookmarks, ntypes) Session = sessionmaker(bind=engine) session = Session() return session if __name__ == "__main__": session = loadSessionLocalNGuidesSQLNew() res = session.query(Bookmarks).all() for a in res: print(dict(filter(lambda item: item[0][0] != '_', a.__dict__.items())))
{'ID': 1, 'Name': 'Размер', 'USort': 1, 'TypeValueID': 2}
{'ID': 3, 'Name': 'Да/Нет', 'USort': 3, 'TypeValueID': 4}
{'ID': 5, 'Name': 'Строка', 'USort': 5, 'TypeValueID': 3}
{'ID': 6, 'Name': 'Целое число', 'USort': 6, 'TypeValueID': 1}
{'ID': 7, 'Name': 'Число', 'USort': 7, 'TypeValueID': 2}
{'ID': 10, 'Name': 'Штриховка', 'USort': 17, 'TypeValueID': 1}
{'ID': 11, 'Name': 'Кортеж свойств', 'USort': 11, 'TypeValueID': 1}
{'ID': 12, 'Name': 'Файлы типа К3|*.k3', 'USort': 12, 'TypeValueID': 3}
{'ID': 13, 'Name': 'Файлы макропрограмм|*.mac;*.py', 'USort': 13, 'TypeValueID': 3}
{'ID': 14, 'Name': 'Файлы картинок|*.jpg;*.bmp;*.wmf;*.gif;*.tiff;', 'USort': 14, 'TypeValueID': 3}
{'ID': 15, 'Name': 'Файлы wmf|*.wmf', 'USort': 15, 'TypeValueID': 3}
{'ID': 16, 'Name': 'Текстура', 'USort': 16, 'TypeValueID': 3}
{'ID': 17, 'Name': 'Цвет К3', 'USort': 17, 'TypeValueID': 1}
{'ID': 18, 'Name': 'Номенклатурная единица', 'USort': 18, 'TypeValueID': 1}
{'ID': 19, 'Name': 'Сборочная единица', 'USort': 18, 'TypeValueID': 1}
[/code
Отредактировано A_L_e_ksandr (Март 3, 2022 19:18:22)
Офлайн
Для начала установи
SQL Server Management Studio (SSMS)
и подключись к своей базе
Когда разберешься - сделаешь уже на питоне
Офлайн
без создания таблицы:
from sqlalchemy import create_engine
engine = create_engine('mssql+pymssql//localhost/mydb')
print(engine)
for row in engine.execute('select * from test'):
print(dict(row))
Офлайн
SQLAlchemy, a popular Python SQL toolkit and Object-Relational Mapping (ORM) library, requires a connection string to establish a connection to a database. The connection string typically contains information such as the database dialect (e.g., PostgreSQL, MySQL, SQLite), the username and password for accessing the database, the host and port of the database server, and the name of the database. For example, a connection string for connecting to a PostgreSQL database might look like this: Kenyan Porn Kutombana Kenyan escorts nairobi escorts nairobiraha telegram porn somali porn
postgresql/username:password@localhost:5432/database_name
This string specifies the PostgreSQL dialect, the username and password for accessing the database, the host (localhost), the port (5432), and the name of the database (database_name).
Офлайн
Using SQLAlchemy's connection string format allows for easy configuration and management of database connections in Python applications. The connection string can be stored in a configuration file or environment variable, making it easy to change aviator database settings without modifying the application code. SQLAlchemy's ORM features Mobile toilets Kenya further simplify database interactions by allowing developers to work with database tables as if they were Python objects, abstracting away the complexities of SQL queries. Overall, SQLAlchemy's connection string format is a powerful tool for managing database connections in gis Python applications.
Офлайн