Solved

Vb Script (Database)

Posted on 2011-09-28
9
242 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb script to unzip a files and rename the files 12 103
Excel .....ActiveWorkbook.SaveAs 12 69
OID and Active Directory Attributes 9 67
Message Logon Windows 2012 R2 Server 16 24
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

14 Experts available now in Live!

Get 1:1 Help Now