Register DSN with SQL Login

K

KevinCB

Hi

I am having problems registering a DSN with SQL Login details.
Before I start getting replies back saying that this is an insecure method,
I am well aware of this but am doing it this way because many people are
going to be using the database and rather than setting permissions for each
individual account, I might as well just create one and apply the DSN to
that. And I can hopefully create a runtime package for this db when it's
finished.

Back to the problem, I have used the code on the Microsoft support site, but
I can't get it to use a username and password login in SQL, only the Windows
Authenticated login.

This is the code I have been using, can anyone help with this?

Function CreateDSNConnection(stServer As String, stDatabase As String,
Optional stUsername As String, Optional stPassword As String) As Boolean
On Error GoTo CreateDSNConnection_Err

Dim stConnect As String

If Len(stUsername) = 0 Then
'//Use trusted authentication if stUsername is not supplied.
stConnect = "Description=Employer Engagement" & vbCr & "SERVER=" &
stServer & vbCr & "DATABASE=" & stDatabase & vbCr & "Trusted_Connection=Yes"
Else
stConnect = "Description=Employer Engagement" & vbCr & "SERVER=" &
stServer & vbCr & "DATABASE=" & stDatabase & vbCr
End If

Debug.Print stConnect

DBEngine.RegisterDatabase "EmpEngage", "SQL Server", True, stConnect

'// Add error checking.
CreateDSNConnection = True
Exit Function
CreateDSNConnection_Err:

CreateDSNConnection = False
MsgBox "CreateDSNConnection encountered an unexpected error: " &
Err.Description

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top