Hi all
I am trying to retrieve the SQL username for the currently logged on
user from my backend SQL Database so i can populate a form.
I have the following 2 procedures. However obviously its always
returning the username SQL as per the connection string. Is there a
way of doing this for the CURRENTLY LOGGED IN USER?? if i remove
credentials from the connection string the procedure fails. Also if i
use 'CurrentProject .connection' this also fails as it refers to a JET
connection
Public Function DB_Connection() As Variant
'DB_Connection = CurrentProject. Connection
Dim strConnection As String
strConnection = "Driver={SQ L
Server};Server= servername;Data base=db;Uid=SQL ;Pwd=SQL;"
DB_Connection = strConnection
End Function
Function Current_SQL_Use r() As Variant
Dim strUserName As Variant
Dim rst As New ADODB.Recordset
With rst
.ActiveConnecti on = DB_Connection
.CursorLocation = adUseClient
.Source = "SELECT suser_sname() "
.Open
strUserName = .Fields(0)
.Close
End With
Set rst = Nothing
strUserName = Username
Current_SQL_Use r = strUserName
End Function
Thanks in advance 2 14101
On Mar 5, 11:51 am, boyl...@gmail.c om wrote:
Hi all
I am trying to retrieve the SQL username for the currently logged on
user from my backend SQL Database so i can populate a form.
I have the following 2 procedures. However obviously its always
returning the username SQL as per the connection string. Is there a
way of doing this for the CURRENTLY LOGGED IN USER?? if i remove
credentials from the connection string the procedure fails. Also if i
use 'CurrentProject .connection' this also fails as it refers to a JET
connection
Public Function DB_Connection() As Variant
'DB_Connection = CurrentProject. Connection
Dim strConnection As String
strConnection = "Driver={SQ L
Server};Server= servername;Data base=db;Uid=SQL ;Pwd=SQL;"
DB_Connection = strConnection
End Function
Function Current_SQL_Use r() As Variant
Dim strUserName As Variant
Dim rst As New ADODB.Recordset
With rst
.ActiveConnecti on = DB_Connection
.CursorLocation = adUseClient
.Source = "SELECT suser_sname() "
.Open
strUserName = .Fields(0)
.Close
End With
Set rst = Nothing
strUserName = Username
Current_SQL_Use r = strUserName
End Function
Thanks in advance
Does this help?
Function GetSqlUser() As String
Dim qrd As DAO.QueryDef, rst As DAO.Recordset
Set qrd = CurrentDb.Creat eQueryDef("")
With qrd
.Connect = CurrentDb.Table Defs(0).Connect
.SQL = "SELECT SYSTEM_USER"
.ReturnsRecords = True
End With
Set rst = qrd.OpenRecords et()
GetSqlUser = rst(0).Value
rst.Close
Set rst = Nothing
Set qrd = Nothing
End Function
hi this works perfectly.
How come you have to use DAO and not ADO, seems silly.
thanks a milion, was really starting to bug me :-)
On 5 Mar, 19:32, "Gord" <g...@kingston. netwrote:
On Mar 5, 11:51 am, boyl...@gmail.c om wrote:
Hi all
I am trying to retrieve the SQL username for the currently logged on
user from my backend SQL Database so i can populate a form.
I have the following 2 procedures. However obviously its always
returning the username SQL as per the connection string. Is there a
way of doing this for the CURRENTLY LOGGED IN USER?? if i remove
credentials from the connection string the procedure fails. Also if i
use 'CurrentProject .connection' this also fails as it refers to a JET
connection
Public Function DB_Connection() As Variant
'DB_Connection = CurrentProject. Connection
Dim strConnection As String
strConnection = "Driver={SQ L
Server};Server= servername;Data base=db;Uid=SQL ;Pwd=SQL;"
DB_Connection = strConnection
End Function
Function Current_SQL_Use r() As Variant
Dim strUserName As Variant
Dim rst As New ADODB.Recordset
With rst
.ActiveConnecti on = DB_Connection
.CursorLocation = adUseClient
.Source = "SELECT suser_sname() "
.Open
strUserName = .Fields(0)
.Close
End With
Set rst = Nothing
strUserName = Username
Current_SQL_Use r = strUserName
End Function
Thanks in advance
Does this help?
Function GetSqlUser() As String
Dim qrd As DAO.QueryDef, rst As DAO.Recordset
Set qrd = CurrentDb.Creat eQueryDef("")
With qrd
.Connect = CurrentDb.Table Defs(0).Connect
.SQL = "SELECT SYSTEM_USER"
.ReturnsRecords = True
End With
Set rst = qrd.OpenRecords et()
GetSqlUser = rst(0).Value
rst.Close
Set rst = Nothing
Set qrd = Nothing
End Function- Hide quoted text -
- Show quoted text -
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robin |
last post by:
Hi all,
I'm working with a VB app, using DAO 3.6, that used to generate Access
'97 databases using the following code:
Set dbsNew = wrkDefault.CreateDatabase(strLPAccessInv, dbLangGeneral,
dbVersion30)
I was able to have it create databases in Access 2000 by changing
"dbVersion30" to "dbVersion40". Do I generate a database in Access
|
by: nick |
last post by:
Is possible for server side code to access the text of <asp:label> changed
by client side javascript code?
|
by: jhcorey |
last post by:
We're using a third-party treeview and found that the functionality we
need
works only when we set the web site security to allow Anonymous Access.
We also need the user's network id, which we could get from
System.Web.HttpContext.User.Identity.Name if we don't allow AA.
Is the user's id somehow still accessible in the app even though we're
using
Anonymous Access?
|
by: jmarr02s |
last post by:
Is it possible to limit the number of Subform records using MS Access
2003?
That is, my end users want the capability of entering up to 12 records
on their subform.
Is that possible?
Thanks!,
|
by: mrowe |
last post by:
I am working on a form in an Access 2003 database (using ADO). The detail section of my form has as checkbox named ‘Select’ that occurs once for each row of data. I have placed another checkbox in the header of the form named ‘SelectAll’. When ‘SelectAll’ is modified, I want to modify every occurrence of the ‘Select’ checkbox in the detail section. I looked through several posts and have played around with the code, but I have received an...
| |
by: PROGRAMMINGMAESTO |
last post by:
How to Fetch and Retrieve image in ASP using MS Access.
--------------------------------------------------------------------------------
Hello Friends,
Can Anybody guide about how should i code to fetch image and save image in Access database. i have used OLE object data type in access database.
Platform : ASP(VB Script)
Database : Ms access
please anybody can help me about this.
|
by: huntress |
last post by:
I am trying to create pivot tables using VBA in Access 2003. Is this possible? How do I go about it?
|
by: Canuno |
last post by:
Hi, I'm trying to send a small string to a serial port rs232 located in com 4.
the string is: "ST GA#Ž"
The Baud Rate is: 38400
Parity: None
Data Bits: 8
Stops Bits: 1
Flow Control: None
COM: 4
|
by: Swan |
last post by:
Can anyone plz tell me,Can I write file on server using binary access,or it is only to write on local?(Actually I am creating OCX for Http File Upload Control in VB using API's.So for that I need to raed file from local and write it to server.)
Thanking you!
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |