Solved

Vb Script (Database)

Posted on 2011-09-28
9
240 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 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

9 Experts available now in Live!

Get 1:1 Help Now