473,659 Members | 3,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to Open a Connection from "inside" a Database?

rm
When using ADO in a module inside an Access 2003 database do I need to
open a db connection even though I am working with a table inside the
same database?

I am writing a bit of code to periodically import data from a text
file to a table in a database. The capabilities of the import wizard
are not sufficient to support what we need for manipulating/parsing
the ascii text file.
Dec 6 '07 #1
5 2521
rm wrote:
When using ADO in a module inside an Access 2003 database do I need to
open a db connection even though I am working with a table inside the
same database?

I am writing a bit of code to periodically import data from a text
file to a table in a database. The capabilities of the import wizard
are not sufficient to support what we need for manipulating/parsing
the ascii text file.
There is a connection available for you

CurrentProject. Connection

Most around here would probably recommend DAO over ADO.

--
Roy-Vidar
Dec 6 '07 #2
rm
On Dec 6, 10:43 am, rm <gro...@rlmoore .netwrote:
When using ADO in a module inside an Access 2003 database do I need to
open a db connection even though I am working with a table inside the
same database?

I am writing a bit of code to periodically import data from a text
file to a table in a database. The capabilities of the import wizard
are not sufficient to support what we need for manipulating/parsing
the ascii text file.
Here is the code...

Sub Import()

Dim fso As New Scripting.FileS ystemObject
Dim tsIn As Scripting.TextS tream
Dim InputFile As String
Dim cmd1 As ADODB.Command

'Values from the file
Dim strX As String
Dim strY As String
Dim strZ As String

InputFile = "C:\temp\exp.tx t"

' Make sure the file exists
If Not fso.FileExists( InputFile) Then
MsgBox "Cannot find input file."
Exit Sub
Else
'Open the input file.
Set tsIn = fso.OpenTextFil e(InputFile)
Set cmd1 = New ADODB.Command
cmd1.CommandTyp e = adCmdText

'############## ############### ############### ##########
' THE FOLLOWING LINE THROWS AN ERROR MESSAGE
'Run-Time error '-2147467259 (80004005)
'The database has been placed in a state by user 'userid' on
machine 'machine-id'
'that prevents it from being opened or locked.
'############## ############### ############### ##########

cmd1.ActiveConn ection = "Provider=Micro soft.Jet.OLEDB. 4.0;
Data Source= p:\mydb.mdb"

'Loop through input file. When at Endof Stream becomes
'True, you've reached the end of the file
Do While Not tsIn.AtEndOfStr eam
buf = tsIn.ReadLine

'if we have a social security number - first 9 #s numeric
' then write record
If IsNumeric(Mid(b uf, 1, 9)) Then
strX = Trim(Mid(buf, 1, 9))
strY = Trim(Mid(buf, 11, 25))
strZ = Trim(Mid(buf, 39, 2))
cmd1.CommandTex t = "INSERT INTO table1(x, y, z)
values('" & strX & "','" & strY & "','" & strZ & "')"

'############## ############### ############### ##########
' THE FOLLOWING LINE THROWS AN ERROR MESSAGE
' BECAUSE I DO NOT HAVE A CONNECTION TO A DB
'############## ############### ############### ##########

cmd1.Execute
End If
Loop

'Close the file
tsIn.Close

'Release object references
Set tsIn = Nothing
Set cmd1 = Nothing
Set fso = Nothing

End If
End Sub
Dec 6 '07 #3
rm
On Dec 6, 11:11 am, RoyVidar <roy_vidarNOS.. .@yahoo.nowrote :
rm wrote:
When using ADO in a module inside an Access 2003 database do I need to
open a db connection even though I am working with a table inside the
same database?
I am writing a bit of code to periodically import data from a text
file to a table in a database. The capabilities of the import wizard
are not sufficient to support what we need for manipulating/parsing
the ascii text file.

There is a connection available for you

CurrentProject. Connection

Most around here would probably recommend DAO over ADO.

--
Roy-Vidar
Sir,

Thank you for the response.

CurrentProject. Connection throws the same error message. - Run-time
error '-2147467256 (80004005)' The database has been placed in a state
by user 'userid' on machine 'machineid' that prevents it from being
opened or locked.

Am I using the connection correctly?

cmd1.ActiveConn ection = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
Source=" & CurrentProject. Connection

Dec 6 '07 #4
rm
On Dec 6, 10:43 am, rm <gro...@rlmoore .netwrote:
When using ADO in a module inside an Access 2003 database do I need to
open a db connection even though I am working with a table inside the
same database?

I am writing a bit of code to periodically import data from a text
file to a table in a database. The capabilities of the import wizard
are not sufficient to support what we need for manipulating/parsing
the ascii text file.
Got it...

cmd1.ActiveConn ection = CurrentProject. Connection

Thank you Roy-Vidar!
Dec 6 '07 #5
rm wrote:
On Dec 6, 11:11 am, RoyVidar <roy_vidarNOS.. .@yahoo.nowrote :
>rm wrote:
>>When using ADO in a module inside an Access 2003 database do I need to
open a db connection even though I am working with a table inside the
same database?
I am writing a bit of code to periodically import data from a text
file to a table in a database. The capabilities of the import wizard
are not sufficient to support what we need for manipulating/parsing
the ascii text file.
There is a connection available for you

CurrentProject .Connection

Most around here would probably recommend DAO over ADO.

--
Roy-Vidar

Sir,

Thank you for the response.

CurrentProject. Connection throws the same error message. - Run-time
error '-2147467256 (80004005)' The database has been placed in a state
by user 'userid' on machine 'machineid' that prevents it from being
opened or locked.

Am I using the connection correctly?

cmd1.ActiveConn ection = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
Source=" & CurrentProject. Connection
Try

Set cmd1.ActiveConn ection = CurrentProject. Connection

--
Roy-Vidar
Dec 6 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8060
by: David Furey | last post by:
Hi I have an XML documnet and a XSLT document as shown below THe XSLT document brings back a filtered docmument that has the VendorName that starts with a particular sub-string This works as expected with alphabet and number characters and the ' (single quote &apos; entity) character but does not work if a double quote character " is part of the string to filter on This returns all Vendor Names that begin with A (either case)
11
4163
by: Pete Wilson | last post by:
Hi folks -- The page at http://www.pwilson.net/submit-demo.html will not validate. The validator at http://validator.w3.org tells me I can't have an input inside a form. Would some kind soul please tell me what I'm doing wrong?
2
2167
by: Joe Lester | last post by:
Does anyone know if there's a way to embed the Postgres database inside an application... so that it runs transparently, without the user even having to know it's there? I would prefer to use Postgres, but I fear that I may have to resort to mySQL or some other SQL database that can be embedded. I'm building a Cocoa app on OS X and am familiar with the libpq C library. Thanks!
10
54587
by: qazmlp | last post by:
There are some blocks of C/C++ code put under #if 0 #end if Is there anyway to make the code inside these blocks to get executed (may be by using some command line options)?
12
2717
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external linkage? Not much on this in the FAQ or tutorials.
2
1624
by: Mehdi | last post by:
Hi, I need to pass an URL via a hidden value as follow: <input type="hidden" id="Test" runat="Server"> and on Page_Load I assign a value to this hidden input as follow: Test.Value = "http://www.myserver.com?id=123&name=HomerSimpson";
3
1653
by: Peter Proost | last post by:
Hi group, I've got this bit of code (see below) which draws a basketball field in a picturebox (width:198, height:368) but now I was wondering what would be the easiest way to check inside the picturebox mouseup event if I clicked inside or outside the 3point area, because the 3point area isn't a real cirkle Any hints or tips are welcome.
0
1057
by: Angrez Singh | last post by:
Hi, I am trying to use a "customcontrol" inside a "webusercontrol" but facing problem with the viewstate of the "customcontrol". When I use the "customcontrol" on a page either adding it statically or dynamically, it works fine. There is no problem with the ViewState. Also when I use this "customcontrol" inside another "customcontrol" there is no problem with the ViewState.
1
1247
by: vbfoobar | last post by:
Hello, I have HTML input to which I apply some changes. Feature 1: ======= I want to tranform all the text, but if the text is inside an "a href" tag, I want to leave the text as it is. The HTML is not necessarily well-formed, so
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.