[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Vb Script (Database)

Posted on 2011-09-28
9
Medium Priority
?
263 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 1000 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
Technology Partners: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 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