Can I share a single database connection between ODBC and ADO? - sql-server

Is it possible to have an ODBC connection and an ADO connection share the same underlying SQL Server connection, so that both are using the same SPID?
Currently I am using SQLDriverConnect and ADODB::_ConnectionPtr->Open. I can make these connections in either order, so perhaps it's possible to open one making use of the other?
(Language is C++, database is SQL Server 2005 & 2008. ODBC connection string uses a DSN. ADO uses Provider=SQLNCLI10, but either could be changed if required).

ADO uses OleDB, so you cannot share a connection with ODBC. Even if you use the ADO provider for ODBC you still wont be able, as no ADO API allows to wrap an existing ODBC connection handle.
But the real question is: why do you want to share the connection? The only valid reason is to enroll the two connections in the same transaction without doing a loopback local distributed transaction. Enrolling two distinct connections in the same transaction was always possible, this is how MTS and COM+ worked. The first connection uses sp_getbindtoken to get an enrolment token and the second connection uses sp_bindsession to enroll itself. This mechanism is on the endangered list of deprecation, but after all you are asking about the technology of the 90s... (ODBC, ADO)

Related

Multiuser SQL Powered Access Database Over Network

I have been creating an access database for my assignment. I am using SQL Server 2014 for the datasource for the access tables. Now the problem is that according to the assignment
I need to make the db multiuser over network
it has to be an accde file
In short, how can I connect to SQL Server when I deploy the database on my college pc. And how to make the accde work on my school network where the SQL Server is not the one I am using at my personal machine.
It is a simple book entry database containing few tables including print button and picture of book attachment.
Use a DSN-less connection. Provide a function that changes the connection string on all linked tables.
See Linked table ms access 2010 change connection string
or Changing SQL connection information for DSN-less Access frontend
You don't want each user having to enter the server information into the frontend. So take your frontend to the school network, run the function to re-link all tables, then create the .accde, then distribute it.
If the sql server is on your same network, then all you have to do is link your tables to the production sql server. You then crate the accDE, and that can be deployed to any machine.
Access by “default” creates a DSN less connection. So if you follow the defaults when linking to sql server (use a FILE dsn), then once access links to those tables, access “converts” the DSN to a DSN less connection for you.
What this means is that you do not need any VBA re-linking code. When using a file dsn, access converts these to DSN less for you. Once linked, then Access ignores and does not use nor require the original DSN.
So your steps are:
Linking to the production SQL server on the network. Just make sure you use the “default” file dsn.
Once you are sure the accDB works with that production SQL server, you can then compile/create the accDE. That accde will now function on ANY workstation (and this work since access by default creates and uses and makes a DSN less connection for you).
You do NOT need any VBA re-link code.
You do NOT have to write some VBA code to create a DSN less connection (access does this automatic for you).
Of course, during this re-link process, your computer will have to be on the same network with the production SQL server you plan to link to.
If you were some off site worker, and you cannot be on the same network during the re-link process, then YES you would have to adopt some VBA code to re-link for you. However, if you can be on the same network during this re-link process, then at that point you can create the accDE file, and it can be distributed to any workstation on that network without further configuration.
About the only issue would be to ensure that you link to this production server using the standard and legacy “SQL Server Driver” as your linking choice. You can use the later “native 11” etc. drivers, but they are not installed by default on each version of windows and thus this ODBC driver may well not be installed on each workstation (but the standard SQL Driver is installed by default.
Again:
You do not need some VBA code or re-link code to create a DSN-less connection. Access by default when choosing a “file” DSN will create DSN-links for you – you thus don’t need any special re-link code, nor do you need some VBA re-link code to achieve DSN-less links.

How to get get data as IQueryable from Sql Server ODBC Connection

I am trying to implement OData over odbc connection layer, I am currently not able to get data as IQueryable from ODBC driver (ODBC connection is for Sql Server)
Is there any driver that can return data as IQueryable through ODBC Connection?
The benefit of IQueryables that they don't actually execute on the database. IQueryables are just in-memory representations of a query that one can execute on demand to get results. It's a flavor of a lazy loaded list.
Given this I don't think that you are necessarily asking the right question. Does that make sense?

Connecting to DB2 through ODBC is extremely slow

I am experiencing extremely slow connections to a local DB2 (v9.7 Express-C) database through ODBC on a Windows 7 system (x64). I wrote several test programs, each connecting to a local database for 100 times in a row (without querying) and measuring the time. Results are:
C++ x86 DB2/ODBC: 32bit C++ application, connecting to a local DB2 database via CDatabase
C++ x86 DB2/ODBC: same as above, but x64 application
PHP DB2/ODBC: Connecting to a local DB2 database via odbc_connect.
PHP MySQL/ODBC: Connecting to a local MySQL database via odbc_connect.
JDBC DB2: Java application, connecting to a local DB2 database using the DB2 JDBC driver.
JDBC MySQL: Java application, connecting to a local MySQL database using the MySQL JDBC driver.
My first thought was that something's wrong with my ODBC configuration, but as you can see connecting to a MySQL database through ODBC works like charm. On the other hand, connecting to DB2 with the JDBC driver instead of ODBC works fine too (although it's still a lot slower than MySQL).
I found this related question, but it does not apply to me.
Any hints on what might be causing this and how to resolve would be great!
Supplementary question: What are common connection times when connecting to a DB2 database through ODBC? Is it normal for the DB2 ODBC driver to be so slow?!
One thing that you should look at is the database activation. DB2 activates the database upon the first connection and deactivates it when the last connection is closed. During activation DB2 allocates transaction log files, memory pools, and performs a number of other tasks that take time.
This behaviour does not depend on the type of connection (ODBC or JDBC); the difference you observe might be explained by an extra connection that keeps the database active during your JDBC tests.
Try issuing ACTIVATE DB <YOURDB> before your tests, which will keep the database active even in the absence of connections. There is no way to activate databases by default, apart from issuing this command upon the system startup, e.g. from a batch file.

Servelt Database Connectivity: JDBC, ODBC, Connection Pooling and

For an exam question, I am looking at the various ways in which a servlet can make a connection to a database connection. So far I have
JDBC
ODBC
Database Pooling
But the question asks for 4, and I cannot seem to find the 4th alternative. Does it actually exist?
I suspect you might want to look at the Java Persistence API. Go Google JPA.
I would add JNDI lookup and connecting directly using DriverManager. And what is database pooling? Do you mean connection pooling?
On the other hand if they are asking about high-level technologies: jdbc -> mybatis -> hibernate -> jpa.
A servlet can't really use ODBC it might be able to use a JDBC via ODBC driver, but the servlet sees only ODBC.
Similarly Connection Pooling just pools JDBC connections. The connections are just made via JDBC.
Since the expected answer is 4 they might be asking for the 4 types of JDBC drivers

Does Entity Framework use database connection pooling? and is it by default?

I have been searching for a while about how EF utilizes connections to SQL Server DB, and whether it is using Connection pools under the hood, but I couldn't find any details about that.
Connection pooling is handled by the underlying datasource provider, and not by the Entity Framework. The MS SQL provider, for example, supports and uses connection pooling by default.
Using Connection Pooling with SQL Server
is a good reference.

Resources