473,662 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can we use dynamic queries on SQL-SERVER without ADO and without apersistent ODBC Connection?

By "dynamic" I mean the use of an SQL string in code.

This is my best to date:

I do not use ODBC frequently. Is there a simpler way?

Public Sub Whatever()
Dim q As DAO.QueryDef
With DBEngine(0)
..BeginTrans
On Error GoTo WhateverErr
Set q = .Databases(0).C reateQueryDef(" Trash" & Format(Now(),
"yyyymmddhhnnss "))
With q
..Connect = "ODBC;DRIVER=SQ L SERVER;SERVER=F FDBA-LAPTOP
\SONYLAPTOP;DAT ABASE=DB_51315; Trusted_Connect ion=yes"
..SQL = "SELECT * FROM FFDBATransactio ns WHERE Year([Date]) = 2007 AND
Month([Date]) = 3"
Debug.Print .OpenRecordset( ).Fields("[Date]").Value ' 2007-03-01
End With
End With
WhateverExit:
DBEngine(0).Rol lback
Exit Sub
WhateverErr:
MsgBox Err.Description
Resume WhateverExit
End Sub

Sep 23 '08 #1
1 2022
Mumbling to myself ...
I think this can be more (than the previous) accurately called
dynamic, as it does not use a saved query, unsaved through the
application of a transaction.

Sub whatever2()
Dim w As DAO.Workspace
Dim c As DAO.Connection
Dim r As DAO.Recordset
Set w = DBEngine.Create Workspace("", "", "", dbUseODBC)
With w
Set c = .OpenConnection ("", _
dbDriverComplet e, _
True, _
"odbc;driver={s ql server};server= ffdba-laptop
\sonylaptop;dat abase=db_51315; trusted_connect ion=yes")
With c
Set r = .OpenRecordset( _
"SELECT * FROM FFDBATransactio ns WHERE Year([Date]) = 2007 AND
Month([Date]) = 3")
End With
End With
Debug.Print r.EOF
End Sub

I think this will not work with DAO < 3.6.

I'm interested because it may give me the kind of direct interaction
that I want with SQL-Server (and that I have with ADO) through ODBC.
Of course, ODBC users may be regular users of such code and I may have
just missed it here.

Yes, I know you're aghast that I haven't released the object
variables. My experience is that such code is unnecessary with DAO >=
3.6.
Sep 23 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2279
by: leileili | last post by:
Hello, Hello, I'm new in dynamic SQL query and I have a problem need help. For example: I have a SQL query like this: select hw.family,hw.id where hw.id="1234567"; and I have a txt file holding more than ten thousands id.
19
6766
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has one, and only one parent. The depth should not exceed 6 or 7 levels. The initial import will have about 6 million leaves, and 3 million branches. I would expect the leaves to grow significantly, in number easily tripling. However, the branches will...
6
3529
by: florian | last post by:
Hello, we are running DB2 UDB EEE Version 7.2 Fixpack 12 on a two machine Windows 2000 Advanced Server Cluster in a dss environment. Some dynamic sql statements for etl processes and even some for online user queries switched overnight from some minutes runtime to a few hours or "never come back" statements. We didn't change a single database or instance parameter. Even the
7
6283
by: Ford Desperado | last post by:
there is an application which issues a lot of simple dynamic queries against an Oracle database. If CURSOR_SHARING is set to FORCE, Oracle treats dynamic queries as static ones, for instance SELECT * FROM SALES WHERE CUSTOMER_ID=12345 Oracle will replace 12345 with a parameter SELECT * FROM SALES WHERE CUSTOMER_ID=:SYS_0 then it will provide 12345 (there is a very convenient setting CURSOR_SHARING just for that). Next time a similar query...
14
14812
by: Ina Schmitz | last post by:
Hello, I would like to get the logical and physical reads for every sql statement executed. Thatfore, I used the command "db2 get snapshot for dynamic sql on <mydatabase>". There, I could see the logical and physical reads from bufferpool for every statement monitored. Am I right? But now, I would like to read these results out of a table so that I could process them automatically. In which table(s) are the results of snapshot for...
4
7192
by: Chris | last post by:
Can't seem to figure out how to do this and have been reading for some time now...... I want to select a row count from a table name in SYSTABLES. This statement does not return what I needed, but can help explain what I'm looking for. I want the results to be the Row Count from a Table Name out of the Sub-Select. Select Count(*) from
2
1708
by: kalaivanan | last post by:
hi, how far dynamic query built inside stored procedures is efficient than normal queries inside stored procedures. does dynamic query have advantage over ad hoc queries and in what way. kalai vanan
11
1459
by: Ronald S. Cook | last post by:
I've read a few posts on the stored procedure vs dynamic sql debate. I ran a few performance test for myself and it appears to be a wash. Given that, I'm leaning toward dynamic sql mostly because it would mean one fewer place to have things. But, before we go that route we wanted to ask the question: Is there any compelling reason why we shouldn't abandon all of our stored procs and just write the SQL inside inside our functions in...
11
13655
by: =?Utf-8?B?U3RlZmFuIFdpbGhlbG0=?= | last post by:
Hello, played a little with orcas and went into a problem by building dynamic queries. I want to build a dynamic where clause but only with parameters that are not empty =(TextBox.Text != ""). Doing this by building a string is very simple, but how to do it with LINQ? string sql = ""; if (TextBox1.Text != "") sql += "Columns_1='"+TextBox1.Text+"'"; if (TextBox2.Text != "")
0
1598
by: lekhrajm | last post by:
Hi, I want to flush Dynamic Sql CACHE completely in db2 9.1.2 I used command "db2 FLUSH PACKAGE CACHE DYNAMIC". But it lefts some queries in cache. These are fixed queries. It creats problem for me to find out top 10 queries with high hit ratio, using table function snap_get_dyn_sql_v91(). These queries come in top 10 most of the time. Is there any way to flush dynamic sql cache completely.
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.