Solved

Vb Script (Database)

Posted on 2011-09-28
9
254 Views
Last Modified: 2012-08-13
I have been playing with ODBC in vbscript I cannot use Macros. I am trying to connect to a database. Once I am connected then I can query the records within it,... but my code is throwing an error. 'object required'

Session.timeout = 15
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "DB1","test","testpass"
Set Session("mydb") = conn

conn.close
set conn = Nothing


please help..

thank you
0
Comment
Question by:drezner7
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36716711
Is this in an ASP script in a true vbscript .vbs file?

Session.timeout wont work in a vbscript, it is for asp
0
 

Accepted Solution

by:
Ashrafedes earned 500 total points
ID: 36716768
Exapmple of MS access connection OLE

I Begining of the page
Imports System.Data.OleDb
        Dim Command2 As OleDbCommand
            Dim SQlcodeupdate As String
            Dim Connection As OleDbConnection
            Connection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & _
                     "Data Source=|DataDirectory|\WeeklyDB_M.accdb ; Mode=Share Deny None")

            Connection.Open()
            SQlcodeupdate = "INSERT INTO [contractor contact] ([ID25], [Cont ID], [Contractor E  name], [Contractor A  name], [GM name], [GM tel], [GM Fax], [Rep name], [Rep Tel], [Rep Email], [Active]) VALUES (@ID25, @Cont_ID, @Contractor_E_name, @Contractor_A_name, @GM_name, @GM_tel, @GM_Fax, @Rep_name,@Rep_Tel, @Rep_Email, @Active_1)"
             Command2 = New OleDbCommand(SQlcodeupdate, Connection)


            Command2.Parameters.AddWithValue("@ID25", DirectCast(FormView1.FindControl("Cont_IDTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@Cont_ID", DirectCast(FormView1.FindControl("Cont_IDTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@Contractor_E_name", DirectCast(FormView1.FindControl("Contractor_E__nameTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@Contractor_A_name", DirectCast(FormView1.FindControl("Contractor_A__nameTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@GM_name", DirectCast(FormView1.FindControl("GM_nameTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@GM_tel", DirectCast(FormView1.FindControl("GM_telTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@GM_Fax", DirectCast(FormView1.FindControl("GM_FaxTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@Rep_name", DirectCast(FormView1.FindControl("Rep_nameTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@Rep_Tel", DirectCast(FormView1.FindControl("Rep_TelTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@Rep_Email", DirectCast(FormView1.FindControl("Rep_EmailTextBox"), TextBox).Text)
            Command2.Parameters.AddWithValue("@Active_1", DirectCast(FormView1.FindControl("ActiveTextBox"), TextBox).Text)
            'Command2.Parameters.AddWithValue("@ID_No", DirectCast(FormView1.FindControl("Cont_IDTextBox"), TextBox).Text)
            Command2.ExecuteNonQuery()

            Connection.Close()
0
 

Author Comment

by:drezner7
ID: 36718120
Neilsr: This is a VbScript
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:mansooralia_yahoo
ID: 36718301
hi drezner

check if you have defined Set Session("mydb")
0
 

Author Comment

by:drezner7
ID: 36718576
Here is what I have


Set conn = Server.CreateObject("ADODB.Connection")
conn.open "DB1","test","testpass"
Set Session("mydb") = conn

conn.close
set conn = Nothing
0
 
LVL 2

Expert Comment

by:mansooralia_yahoo
ID: 36718654
can you try adding these lines

dim conn
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36718806
Can you clarify because other posters are assuming that this all sits in an ASP web page and I am assuming that this is in a .VBS script file run from a windows machine and NOT from a web server/page?

Wich is it please?
0
 

Author Comment

by:drezner7
ID: 36891816
This is a VbScript that runs on a windows OS....
0
 

Author Closing Comment

by:drezner7
ID: 37543960
The solution got me started, but i had to change it to work with VBScript
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question