Kenny Bones
Kenny Bones

Reputation: 5129

VBscript - SQL Connection fails SQL Server does not exist or access denied

this is pretty strange. I've got this string that connect to a SQLServer in the same domain as the computers are running and compares username with employeeID. Then takes that row and dumps it into the lokal computers registry. This is working in Windows XP, but not Windows 7 it seems.

I get this exact error message:

Line:39
Char:1
Error: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied. 
Code: 80004005
Source: Microsoft OLE DB Provider for SQL Server. 

This is the script itself. I've removed the actual servernames. Reckon nobody needs those.

Set oConn = CreateObject("ADODB.Connection")
oConn.Open "Provider=sqloledb;Data Source=mysqlserver04\mysqlserver04;Initial Catalog=orginfo;Integrated Security=SSPI"
sSQL = "select top 1 * from dbo.Mal_personinfo where empid = '" & EID & "'"
'wscript.echo sSQL
set rs = oConn.Execute(sSQL)

set oSystem = CreateObject("WScript.Shell")
for iTeller = 0 to rs.fields.count - 1
    Text = Text & rs.fields(iTeller).Name & "=" & rs.fields(iTeller).Value & " - "
    oSystem.RegWrite "HKCU\Software\MalData\" & rs.fields(iTeller).Name,rs.fields(iTeller).Value,"REG_SZ"
next
'wscript.echo Text

Why does this work on Windows XP but not Windows 7?

Upvotes: 0

Views: 5602

Answers (1)

Kate Gregory
Kate Gregory

Reputation: 18944

Since you're using integrated security, let me ask you about the account that is running the application. Did you add that account as a user to the database? If not, and it's an admin account, you're probably relying on the old "admins can do everything" and under Windows 7 that's not true any more.

To test this, try running the application elevated (right click the exe and Run As Administrator.) This will cause it to keep your "admin-ness" and might let it into the database. If that works, don't continue to run it elevated, but instead go to SQL and add yourself as a user. Then the app should work fine non-elevated.

Upvotes: 1

Related Questions