Hello all,
I have this peice of code that connects to a SQL server without the DSN -
Dim cn As ADODB.Connection
-
Dim rs As ADODB.Recordset
-
-
'Create a new ADO Connection object
-
Set cn = New ADODB.Connection
-
-
'Use the Access 10 and SQL Server OLEDB providers to
-
'open the Connection
-
'You will need to replace MySQLServer with the name
-
'of a valid SQL Server
-
With cn
-
.Provider = "Microsoft.Access.OLEDB.10.0"
-
.Properties("Data Provider").Value = "SQLOLEDB"
-
.Properties("Data Source").Value = "SERVER"
-
.Properties("User ID").Value = "username"
-
.Properties("Password").Value = "password"
-
.Open
-
End With
-
-
'Create an instance of the ADO Recordset class, and
-
'set its properties
-
'Set rs = New ADODB.Recordset
-
With rs
-
Set .ActiveConnection = cn
-
.Source = "SELECT field1, field2 FROM table WHERE field1=1234 order by pk01;"
-
.LockType = adLockOptimistic
-
.CursorType = adOpenKeyset
-
.Open
-
End With
-
-
'Set the form's Recordset property to the ADO recordset
-
Set Me.Recordset = rs
-
Set rs = Nothing
-
Set cn = Nothing
-
It works fine on form load, but when i change it to form current, when the form is loaded up, access actually crashes!!
Thanks
4 3404
okay, new development, if I go through the code with a break, it keeps looping through the code time and time again until access crashes
ADezii 8,834
Recognized Expert Expert
Hello all,
I have this peice of code that connects to a SQL server without the DSN -
Dim cn As ADODB.Connection
-
Dim rs As ADODB.Recordset
-
-
'Create a new ADO Connection object
-
Set cn = New ADODB.Connection
-
-
'Use the Access 10 and SQL Server OLEDB providers to
-
'open the Connection
-
'You will need to replace MySQLServer with the name
-
'of a valid SQL Server
-
With cn
-
.Provider = "Microsoft.Access.OLEDB.10.0"
-
.Properties("Data Provider").Value = "SQLOLEDB"
-
.Properties("Data Source").Value = "SERVER"
-
.Properties("User ID").Value = "username"
-
.Properties("Password").Value = "password"
-
.Open
-
End With
-
-
'Create an instance of the ADO Recordset class, and
-
'set its properties
-
'Set rs = New ADODB.Recordset
-
With rs
-
Set .ActiveConnection = cn
-
.Source = "SELECT field1, field2 FROM table WHERE field1=1234 order by pk01;"
-
.LockType = adLockOptimistic
-
.CursorType = adOpenKeyset
-
.Open
-
End With
-
-
'Set the form's Recordset property to the ADO recordset
-
Set Me.Recordset = rs
-
Set rs = Nothing
-
Set cn = Nothing
-
It works fine on form load, but when i change it to form current, when the form is loaded up, access actually crashes!!
Thanks
It sounds as if the Form's Current() Event is being fired for every Record in the underlying Recordset as it may very well be since it is dynamically assigned. Why would you want to place this code in this Event, anyway?
Is this line intentionally commented out (Line 22)? - 'Set rs = New ADODB.Recordset
No, I commented it out so i could fire up the forms and then uncommented it out for the post!
I wonder if its doing it for every record in the database - for now, i think ill do it in another form that pops up.
If you can think of a solution - let me know.
Thanks
ADezii 8,834
Recognized Expert Expert
No, I commented it out so i could fire up the forms and then uncommented it out for the post!
I wonder if its doing it for every record in the database - for now, i think ill do it in another form that pops up.
If you can think of a solution - let me know.
Thanks
matthooper, just for curiosity - whay can't you place the code in the Form's Load Event?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: shank |
last post by:
I'm trying to setup an Access DSNLess connection on my local computer. The
following string works fine within the Dreamweaver interface. But when I
upload to my server (locally) I get this error. Can anyone lend some
insight?
thanks
Object required: 'oConn'
/Connections/conn.asp, line 2
<%
|
by: Tony Epton |
last post by:
<crossposted to several groups>
Is there any way to create a DSNless connection to SQL server from
access 97 (DAO)
All the samples of connection strings I am finding - all have a
reference to a DSN.
Many thanks
Tony
|
by: Derrick |
last post by:
Trying this code in the Page_Load of a C# web page...
private void Page_Load(object sender, System.EventArgs e)
{
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\MyAccessDb.mdb;";
OdbcConnection conn = new OdbcConnection(connstr);
conn.Open();
...
|
by: pradeep_TP |
last post by:
Hi all,
I have a few questions that I have been wanting to ask for long. These are
all related to ADO.net and specifically to conenction to database.
1) If I have opened a connection to a database through Connection.open()
method, and I do not use Connection.close() method, will garbage collector
collect the connection object just because i am not using it any more.
2) I am using a dataset, in which i make some modifications to the...
|
by: MrsBean |
last post by:
I've been working on learning how to use PHP with MS Access, and as
long as I use ODBC, I can make it work. I want to use a DSNless
connection. Everthing I have tried has failed. Can anyone show me a
simple example?
MrsBean
| |
by: hmyers |
last post by:
We have converted an Access 97 database to Access 2000 on an XP
machine. The application uses a DSN-less connection:
adoConn1.Open "DRIVER={iSeries Access ODBC Driver};" & _
"SYSTEM=SystemName;DBQ=LibraryName,Libraries;", sUserID, sPassword
This fails everytime with an error message saying "Password for
<sUserIdon server <SystemNameis not correct..."
The user enters their userid and password via a form created in the
|
by: fniles |
last post by:
I am using VS2003 and connecting to MS Access database.
When using a connection pooling (every time I open the OLEDBCONNECTION I use
the exact matching connection string),
1. how can I know how many connection has been used ?
2. If the maximum pool size has been reached, what happens when I call the
method Open to open the connection ? Will I get an error ? MSDN says the
request is queued, but will I get an error in the open method ?
...
|
by: Dököll |
last post by:
Hiya Fans!
I hit a brick wall. I was attempting to make a DSNLess connection I seemed to have Goofed somewhere:
Private Sub SQLServer_Click()
Dim MyWorkspace As DAO.Workspace
Set MyWorkspace = CreateWorkspace("", "admin", "", dbUseODBC)
Dim MyConnection As DAO.Connection
Set MyConnection = MyWorkspace.OpenConnection("", , , "ODBC;DATABASE=FirstSQLDB")
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
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...
| |