Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript connect to SQL server 2005

Status
Not open for further replies.

timgerr

IS-IT--Management
Jan 22, 2004
364
US
Hello all, I have a question for ya. I have an inventory script that I have been using on mu SQl 2K DB's and it works great but we have a new SQL 2005 and I am unable to connect to it with vb using the a local 2005 db account.
I created a user in SQL 2005 and attached that user to a database. I am able to create a local ODBC to the sql 2005 database fine using the locally created account. But when I try and connect with my script the 2005 server does not connect. Here is my code:
Code:
Public Function GDAIS(strCPU)
		Const adOpenStatic = 3
		Const adLockOptimistic = 3
		
		Set objConnection = CreateObject("ADODB.Connection")
		Set objRecordSet = CreateObject("ADODB.Recordset")
		
' 		objConnection.Open _
' 		     "Provider=SQLOLEDB;Data Source=MeServerName;" & _
' 		        "Persist Security Info=True;Initial Catalog=LANDesk;" & _
' 		             "User ID=XXX;Password=XXXXX;"
		objConnection.Open _
			"Provider=sqloledb;" & _ 
		    "Data Source=MeServerName;" & _
		    "Initial Catalog=LANDesk;" & _
		    "User Id=XXX;" & _
			"Password=XXXXXX"

		objRecordSet.Open "SELECT Computer.DeviceName FROM LANDesk.dbo.Computer Computer WHERE(Computer.DeviceName='"& strCPU &"')", _
		        objConnection, adOpenStatic, adLockOptimistic
		
		objRecordSet.MoveFirst
		If objRecordSet.RecordCount > 0 Then
			GDAIS = "GDAIS-lddb"
		End If 
		
	
		
		objRecordSet.Close
		objConnection.Close
	End Function
Is there something different in SQL 2005 that I need to know???

Thanks,
timgerr

-How important does a person have to be before they are considered assassinated instead of just murdered?
So there you go! You're the retarded offspring of five monkeys having butt sex with a fish-squirrel! Congratulations!


 
This is what i use:

Code:
'Database Connection String
Set objConn = CreateObject("ADODB.Connection")
    objConn.Open "Driver={SQL Server};" & _
                 "Server=YourServer\DatabaseInstance;" & _
                 "Database=DatabaseName;" & _
                 "user id=username;" & _
                 "password=password;"

Works good for me.



RoadKi11

"This apparent fear reaction is typical, rather than try to solve technical problems technically, policy solutions are often chosen." - Fred Cohen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top