KleinerTipp zu ConnectionString (ADO / VBA) im SQL Server - Updated
english Version at the end
Ein kleiner Tipp zum (VBA / ADO) Connection-String des SQL Servers (getestet mit: Win10 64bit / Access 2013 32-bit / SQL Server 2017):
' ADOConn.ConnectionString = "Driver={SQL Server};Server=localhost\SQLEXPRESS;Database=Northwind;Trusted_Connection=Yes;APP=MeinName\MeinPC\MyApp1;"
' ADOConn.ConnectionString = "Provider='sqloledb';Data Source='localhost\SQLEXPRESS';Initial Catalog='Northwind';Trusted_Connection=yes;APP=MeinName\MeinPC\MyApp2;"
' ADOConn.ConnectionString = "Provider=SQLNCLI11;Server=localhost\SQLEXPRESS;Database=Northwind;Trusted_Connection=yes;APP=MeinName\MeinPC\MyApp3;"
' ADOConn.ConnectionString = "Driver={SQL Server Native Client 11.0};Server=localhost\SQLEXPRESS;Database=Northwind;Trusted_Connection=Yes;APP=MeinName\MeinPC\MyApp4;"
' ADOConn.ConnectionString = "Driver={SQL Server};Server=localhost\SQLEXPRESS;Database=Northwind;User ID=sa;Password=MyPW;APP=MeinName\MeinPC\MyApp5;"
' ADOConn.ConnectionString = "Provider='sqloledb';Data Source='localhost\SQLEXPRESS';Initial Catalog='Northwind';User ID=sa;Password=MyPW;APP=MeinName\MeinPC\MyApp6;"
' ADOConn.ConnectionString = "Provider=SQLNCLI11;Server=localhost\SQLEXPRESS;Database=Northwind;User ID=sa;Password=MyPW;APP=MeinName\MeinPC\MyApp7;"
' ADOConn.ConnectionString = "Driver={SQL Server Native Client 11.0};Server=localhost\SQLEXPRESS;Database=Northwind;User ID=sa;Password=MyPW;APP=MeinName\MeinPC\MyApp8;"
SELECT App_Name()
abrufen.
Achtung: Überschreibt den APP-Wert der "normalerweise" übergeben würde.
Idee: Auch wenn man mit "normalisierten" Logins arbeitet, so kann man, wenn man pro User einen individuellen Connection-String zusammenbastelt, diesen an den SQL Server übergeben und man hat dann immer den "richtigen" Computer\Usernamen , so als ob man mit Trusted Connection arbeiten würde. Finde ich praktischer, als jedesmal in der Abfrage den Usernamen explizit übergeben zu müssen ... Zudem kann es einem die Fehlersuche auf dem SQL Server wesentlich erleichtern ...
Funktioniert mit allen oben angegebenen Connectionstrings
------------------------------------------ english Version ------------------------------------------
Small tip for using VBA ADO connection-string for SQL Server: (Tested in Win10 64bit / Access 2013 32-bit / SQL Server 2017)
' ADOConn.ConnectionString = "Driver={SQL Server};Server=localhost\SQLEXPRESS;Database=Northwind;Trusted_Connection=Yes;APP=MeinName\MeinPC\MyApp1;"
' ADOConn.ConnectionString = "Provider='sqloledb';Data Source='localhost\SQLEXPRESS';Initial Catalog='Northwind';Trusted_Connection=yes;APP=MeinName\MeinPC\MyApp2;"
' ADOConn.ConnectionString = "Provider=SQLNCLI11;Server=localhost\SQLEXPRESS;Database=Northwind;Trusted_Connection=yes;APP=MeinName\MeinPC\MyApp3;"
' ADOConn.ConnectionString = "Driver={SQL Server Native Client 11.0};Server=localhost\SQLEXPRESS;Database=Northwind;Trusted_Connection=Yes;APP=MeinName\MeinPC\MyApp4;"
' ADOConn.ConnectionString = "Driver={SQL Server};Server=localhost\SQLEXPRESS;Database=Northwind;User ID=sa;Password=MyPW;APP=MeinName\MeinPC\MyApp5;"
' ADOConn.ConnectionString = "Provider='sqloledb';Data Source='localhost\SQLEXPRESS';Initial Catalog='Northwind';User ID=sa;Password=MyPW;APP=MeinName\MeinPC\MyApp6;"
' ADOConn.ConnectionString = "Provider=SQLNCLI11;Server=localhost\SQLEXPRESS;Database=Northwind;User ID=sa;Password=MyPW;APP=MeinName\MeinPC\MyApp7;"
' ADOConn.ConnectionString = "Driver={SQL Server Native Client 11.0};Server=localhost\SQLEXPRESS;Database=Northwind;User ID=sa;Password=MyPW;APP=MeinName\MeinPC\MyApp8;"
If having a user individual APP=MeinName\MeinPC\MyAppN;
then one can fetch that with
SELECT App_Name()
Pay Attention: Overwrites the "original" APP value (which "normally" would be passed)
Idea behind: Using an indiviual ADO Connection-String per user with VBA is simpler than passing the computer\user each time as parameter. So one is able to have the same information for "computer\user" even if not working with Trusted_connection but with "normalized" login-strings, without transmitting each time explicit user-name parameter ... Additionally it eases the debugging a lot as you know exactly which user etc ...
Does work with all shown ConnectionStrings
Maybe helpful ?
Print article | This entry was posted by klausobd on 15.11.17 at 03:50:00 . Follow any responses to this post through RSS 2.0. |