Query Timeout Settings in Excel - sql-server-2005

new to the site I'd like to give it a shot and see if I can get any answers regarding SQL Querys in Excel.
Is there a way to handle if a Timeout occurs in Microsoft Excel (mostly 2007/2010 on Win XP/Vista/7)? As you know you can connect Excel to a Microsoft SQL Server and run your query via Excel. The only thing is that I don't seem to find any Timeout options for this. And for an example, if there is a bad query, this might lock other tables in the SQL Server (2005) database.
I'm not looking for a script. It's more like settings I need and if possible I would like to add these Timeout settings to a specific Windows user account. Settings in either SQL Server 2005 or in Microsoft Excel 2007/2010.
Best regards
/Henrik

Use the CommandTimeout property
Dim objCommand As ADODB.Command
Set objCommand = New ADODB.Command
objCommand.CommandTimeout = 99 '
objCommand.ActiveConnection = cnConn
objCommand.CommandText = "DELETE Users WHERE IdLevel < 98"
objCommand.Execute

Related

Connect Microsoft Access to phppgadmin to query in PostgreSQL

My goal is to import data into Microsoft Access to create a database which I can reference from an excel dashboard for analysis.
I can't find any information on how to connect access to allow me to query the database on phpPgAdmin.
Any advice, direction or solution is highly appreciated.
Please let me know if there more details are necessary.
MS Access is a multifaceted thing as many tend to conflate and confuse its frontend GUI .exe application and the distinct backend database (JET/ACE SQL engine which are Windows .dll files). Most of the time we refer to its MS Office app. Technically, MS Access is really the same type of product as phppgadmin: a GUI console to a database, only its default database is the aforementioned engine but can also integrate other ODBC/OLEDB-connected backends including Postgres, Oracle, MySQL, SQL Server, etc.
Through various means, you can integrate MS Access as a medium between PostgreSQL and Excel without any single migration (export/import) of data.
Linked Tables - Directly connect to Postgres tables using its ODBC Driver.
Pass-through queries - Create saved queries using Postgres dialect within MS Access.
ADO Connections (see Importing data programmatically and by using functions) - Bypass MS Access and have Excel connect directly to Postgres also using OLEDB provider or ODBC driver. Below is the programmatic version showing two connection string examples, but you can save connection objects via the Excel ribbon UI.
Dim strConnection
' REFERENCE Microsoft ActiveX Data Objects, #.# Library
Dim conn As ADODB.Connection, rst As ADODB.Recordset
' ODBC AND OLEDB CONNECTIONS (SELECT ONE)
strConnection = "Driver={PostgreSQL};Server=IPaddress;Port=5432;" _
& "Database=myDataBase;Uid=myUsername;Pwd=myPassword;"
strConnection = "Provider=PostgreSQL OLE DB Provider;Data Source=myServerAddress;" _
& "location=myDataBase;User ID=myUsername;password=myPassword;"
conn.Open strConnection
rst.Open "SELECT * FROM myPGTable", conn
By the way, above is the VBA version to be run in an Excel macro but ADO is a COM object and hence can be integrated in COM-interfaced languages including PHP, Python, R, Java, etc.

Connecting to integrated SQL Server in Visual Studio 2016

I'm trying to use OLE DB to connect to the SQL Server that shipped with VS2015 (this should be SQL Server Express I think). Actually I have problems getting my connection string set up. All my attempts resulted in a generic error message.
The errors occurred with this line of code afterwards:
oCon = New OleDbConnection(cConnectstring)
I tried following connection strings:
Server=localhost;Database=main_Table;Trusted_Connection=True;
As well as:
Provider=SQLNCLI11;Data Source=(localdb)\MSSQLLocalDB;DataTypeCompatibility=80;Initial Catalog=main_Table;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
Or:
Provider = sqloledb;Data Source=(localdb)\MSSQLLocalDB; Initial Catalog = main_Table;Integrated Security=SSPI;
where main_Table is the table I try to start with. I used the connection string that I get via right click on that table in the DB explorer as well (that worked for my Access DBs flawlessly).
Does anybody know how to make this work with Ole DB and SQL Server 2016?
Thanks.

Connect SQL Express 2012 vb.net

I have been working on this for a few days now. I am trying to make vb.net forms app for my database. Right now I am working on a login form and a main form. I have researched many different websites and played with this string forever, but i can not get a connection to my db. I get different errors saying the machine refused it, then ill get a timeout error, then it will go back to refusal.
Dim conn As New MySqlConnection
If conn.State = ConnectionState.Closed Then
conn.ConnectionString = ("Server=192.168.0.2;Database=Sunshinetix;User=sa;Password=sunshine;")
End If
Can someone please tell me what I am doing wrong? I am a beginner in vb.net. And this is a remote server, but LAN.
Thanks!
PS: Is is because I am using SQL Express?
Enable remote connections for SQL Server Express 2012
I've had that article open for a few days and it has helped me a lot to this point.
If you are using Sql Server express, you need to use a SqlConnection, not a MySqlConnection. That one is for use with MySQL, which is a different implementation of SQL than Microsoft SQL Server
Of course, Microsoft also offers the OleDbConnection as kind of a "catch-all" (see more here: Difference between Sql Connection and OLEDB Connection). Still, if I know I'm going to stick with a particular SQL provider, then I generally use the specialized version.
Also, if you're ever interested, here is a small list of common SQL providers:
Microsoft SQL Server - proprietary SQL provider developed and supported by Microsoft
MySQL - Free, open source relational database system developed by Oracle. Very popular with web developers.
PostgreSQL - another open-source RDBMS. Gaining popularity due to its flexibility and adherence to standards.
SQLite - a small, SQL provider with an emphasis on portability. Unlike the others, it uses local database files rather than a remote server. This has made it pretty much the default choice when developing mobile applications that require local storage.
Try this:
Dim SQLConn As SqlConnection = New SqlConnection
SQLConn.ConnectionString = "Data Source=servername;" & _
"Initial Catalog=databasename;" & _
"User ID=username;" & _
"Password=userpassword;"
The reason why you can't connect is that you are using MySQLConnection that is connectiong to connecting to MySQL DB which is different from MS SQL so you need to use SqlConnection
You might also check this:
http://support.microsoft.com/kb/308656
Also check this site:
http://www.connectionstrings.com/sql-server/
To know preferences of your SqlConnection string according to SQL version.
Try this to test your connection string:
Dim connectString as String = ""
Try
Dim objConn As SqlConnection = New SqlConnection(Server=192.168.0.2;Database=Sunshinetix;User=sa;Password=sunshine;)
objConn.Open()
objConn.Close()
Msgbox("Successfully connected to database!")
Catch ex As Exception
Msgbox("Cannot connect, Error:" & ex.Message)
End Try

VBA Timeout DoCmd.RunSQL Insert

Having a problem with a MS Access application that is throwing an ODBC connection timeout error on a DoCmd.RunSQL with an insert on a MS SQL Server linked table.
I've tried using:
Dim Mydb As Database
Set Mydb = CurrentDb
Mydb.QueryTimeout = 900
per the closest MSDN I could find, but did not work. I can insert into that SQL DB with less than 3-seconds query run time from SQL Management Studio, but from Access it gives this timeout.
Anyone else ran into the issue and/or found a remedy?
I would suggest creating a pass through query for this. With the pass through query you can set the timeout option on the property sheet. It is listed as
ODBC Timeout
If you set this to 0 it will wait until the query returns records. The other great thing about the pass through query is the SQL Server is what is doing the actual work and then it returns all of the records back to Access so it runs more efficient.
When you open the query in design view, there is a property ODBC Timeout. (Right click in blank -> Properties)
Have you tried setting it to 0 (infinite) or to a higher value?
It works for me!

access to SQL copy

We have an Access DB which has a set of local tables and input forms etc. in which a user maintains their data.
We also have a SQL DB with the same tables which is used to displays the data in a web search form.
What is the best way to allow the user to udate his changes to the SQL db while keeping the working copy local so he can work offline and then push the files when he is happy with new version of the data?
My first thought was add the SQL tables as linked tables I could then truncate (access does like that) or delete the content in each table and then do an insert for each table.
Can I call a SP from access on the SQL to truncate the tables as I am have problem running deletes
I really do want to get it down to the user running a macro/sql call that is repeatable etc.
Thanks for your help
You should be able to use the ADODB.Command object to execute stored procedures.
EDIT:
This example is copied from Using ADO in VB and Access
Sub ADO_COMMAND_CONNECTION_TEST()
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
Dim strConn As String
cmd.ActiveConnection = " DRIVER={SQL Server};" & _
"Server=UKDUDE;DATABASE=pubs;UID=sa;PWD=;"
cmd.CommandText = "byroyalty"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Refresh
cmd.Parameters(1).Value = 25
Set rs = cmd.Execute
' Recordset now has authors with 25% royalty.....
End Sub
Don't ever use MS Access linked tables with MS SQL.
Not only are they slow, but Access can leave open client-side write cursors on the tables referenced. That's a really dumb way to create lots of deadlocks, but Access does it anyway.
Microsoft significantly improved this when they added Access Data Projects - in these the entire back end is replaced with SQL and Access just supplies the forms.
If you want user actions to write directly back then ADPs are by far the best method.
If you want to cache changes locally in your Access DB and then send them up to SQL you have a far more complex problem. You will need to be far more specific on exactly how you want synchronisation to happen - for instance if two users make offline changes who wins when they connect?
I don't understand why you just don't link directly to the SQL Server data and use it directly, rather than going to the trouble of maintaining a second copy of it. This is the standard Access way to do things -- why are you resisting the natural capabilities of the tool you're using?