Solved

Vb Script (Database)

Posted on 2011-09-28
9
236 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
  • 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
 
LVL 2

Expert Comment

by:mansooralia_yahoo
ID: 36718301
hi drezner

check if you have defined Set Session("mydb")
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now