-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.py
More file actions
67 lines (60 loc) · 1.48 KB
/
Copy pathinsert.py
File metadata and controls
67 lines (60 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pyodbc
SERVER = 'host'
DATABASE = 'database_name'
USERNAME = 'user'
PASSWORD = 'password'
#connectionString = f'DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={SERVER};DATABASE={DATABASE};UID={USERNAME};PWD={PASSWORD}'
connection_string = (
f"DRIVER={'ODBC Driver 18 for SQL Server'};SERVER=tcp:remplace_host,1433;"
f"DATABASE=consignas;Uid=user;Pwd={'password'};Encrypt=yes;"
f"TrustServerCertificate=no;Connection Timeout=30;"
f"DSN=my_dsn"
)
try:
# Connect to the database
connection = pyodbc.connect(connection_string)
# Create the table
cursor = connection.cursor()
cursor.execute(
"""
INSERT INTO [dbo].[table_name]
(
Id,
Matricula,
Bimas,
Informacion_complemetaria,
Fecha_inicial,
Fecha_final,
Observaciones,
Creada_por,
Consigna_
)
VALUES
(
?,
?,
?,
?,
?,
?,
?,
?,
?
)
""",
130,
"fac4110",
234,
"hola",
"2023-11-01",
"2023-11-08",
"test",
"At. Gallego Franco Diego",
"gracias carlos"
)
# Commit the changes
connection.commit()
# Close the connection
connection.close()
except Exception as e:
print(f"Error: {e}")