User is null..?

K

Kent Johnson

Hi all,

I have this script which is supposed log me in to a SQL-server (not trusted)
from Access.

ServerName = "MyServer"
DatabaseName = "MyDb"
UserName = "MyUser
Password = "MyPwd"

Set tdfCurrent = dbCurrent.CreateTableDef(typNewTables(intLoop).TableName)
tdfCurrent.Connect = "ODBC;DRIVER={sql
server};DATABASE=" & _
DatabaseName & ";SERVER=" & ServerName & _
";Uid=" & UserName & ";" & _
"Pwd=" & Password
tdfCurrent.SourceTableName = typNewTables(intLoop).SourceTableName
dbCurrent.TableDefs.Append tdfCurrent

....but Im promted by ODBC:
"Login failed for user (null). Reason: not associated with a trusted SQL
server connection"

What can be wrong?

/Kent J.
 
D

Douglas J. Steele

It can't be copied-and-pasted: there's no closing quote on UserName =
"MyUser.

BTW, do you have Option Explicit turned on?
 
K

Kent Johnson

Yes, you are right.
I erased the closing quote in the message when I changed the userid from the
real username.
I have Option Explicit turned off.

Maybe one solution is to set up a one-way-trust to my SQL-server.
But I guess that this must be done on the domain controller.

/Kent J.
 
D

Douglas J. Steele

You should always have Option Explicit turned on: it can help immensely.

Try turning it on and compiling your code. While it certainly looks as
though you're using the same variable in both places, perhaps it's not
seeing it as the same variable.

For that matter, where have you defined those values versus the rest of the
code?
 
K

Kent Johnson

OK!
I have now Option Explicit turned on.
Sub FixConnections()
Dim DatabaseName As String, Username As String, Password As String,
servername As String
servername = "Myserver"
DatabaseName = "MyDb"
Username = "MyUsername"
Password = "MyPwd"

But I have the same problem.

/Kent J.
 
D

Douglas J. Steele

I'm running out of ideas! <g>

What exactly is in your Connect property? Does it look correct? Based on
your values, it should be:

ODBC;DRIVER={sql
server};DATABASE=MyDb;SERVER=Myserver;Uid=MyUsername;Pwd=MyPwd

What happens if you create a pass-through query and paste that string into
the query as its Connect string?
 

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

Similar Threads

Connection String Madness 0
Access 2000 DSN-Less connections 10
dsn-less connection 4
DSN-Less Connection Error 2
DSNLes Connection 1
ODBC problem 0
DSN-Less connections with MS Oracle Driver 4
connect dns less..? 6

Top