简体   繁体   中英

Table Lock - Timeout - ADO connection to SQL server via Excel VBA

I have a spreadsheet set up to connect to SQL Server via ADO connections. It works by once something is typed into Excel a connection to SQL Server is opened and I then grab variables from the excel document to input into the database. This is my code:

SQLConnect = "Provider=sqloledb;Integrated Security=SSPI;" & _
"Data Source=NCCHAR9\PDS_SSQL; Database=MWPMO; " & _
"Persist Security Info=False;"
Conn1.ConnectionString = SQLConnect
Conn1.CursorLocation = adUseClient
Conn1.Mode = adModeReadWrite
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "UPDATE Input_Tracker SET " & varCol & " = NULL WHERE [ID] = " & varKey & ""
Cmd1.Execute
Cmd1.CommandText = "INSERT INTO Input_Changes(ID, TableName, ColumnName, OldData, NewData, UserID, DateTime) " _
                 & "VALUES('" & varKey & "','" & tblnm & "','" & varCol & "','" & Oval1 & "','" & varData & "','" & username & "','" & Now() & "')"
Cmd1.ExecuteConn1.Close
Set Conn1 = Nothing

My problem is that somehow this code is locking the table in SQL server from being updated every once in a while. I am not the administrator of the database but I did have them take a look and they were unable to find anyone locking the table. Is there something wrong with my code to create this intermittant issue? What can I do?

Ok, So I did more digging, and apparently the table is getting locked because of the select statement built in the "Get External Data Sources" data connection in Excel. Now I guess I need to figure out how to stop the table from getting locked through Excel unless there is a way I can force SQL server to not allow locks, is that possible?

I think the problem can be fixed by writing a link to SQL server via VBA. Searching further...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM