473,698 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DSNless ADO connection

37 New Member
Hello all,

I have this peice of code that connects to a SQL server without the DSN

Expand|Select|Wrap|Line Numbers
  1.   Dim cn As ADODB.Connection
  2.   Dim rs As ADODB.Recordset
  3.  
  4.    'Create a new ADO Connection object
  5.   Set cn = New ADODB.Connection
  6.  
  7.    'Use the Access 10 and SQL Server OLEDB providers to
  8.    'open the Connection
  9.    'You will need to replace MySQLServer with the name
  10.    'of a valid SQL Server
  11.    With cn
  12.       .Provider = "Microsoft.Access.OLEDB.10.0"
  13.       .Properties("Data Provider").Value = "SQLOLEDB"
  14.       .Properties("Data Source").Value = "SERVER"
  15.       .Properties("User ID").Value = "username"
  16.       .Properties("Password").Value = "password"
  17.       .Open
  18.    End With
  19.  
  20.    'Create an instance of the ADO Recordset class, and
  21.    'set its properties
  22.    'Set rs = New ADODB.Recordset
  23.    With rs
  24.       Set .ActiveConnection = cn
  25.       .Source = "SELECT field1, field2 FROM table WHERE field1=1234 order by pk01;"
  26.       .LockType = adLockOptimistic
  27.       .CursorType = adOpenKeyset
  28.       .Open
  29.    End With
  30.  
  31.    'Set the form's Recordset property to the ADO recordset
  32.    Set Me.Recordset = rs
  33.    Set rs = Nothing
  34.    Set cn = Nothing
  35.  
It works fine on form load, but when i change it to form current, when the form is loaded up, access actually crashes!!

Thanks
May 16 '07 #1
4 3404
matthooper
37 New Member
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
May 16 '07 #2
ADezii
8,834 Recognized Expert Expert
Hello all,

I have this peice of code that connects to a SQL server without the DSN

Expand|Select|Wrap|Line Numbers
  1.   Dim cn As ADODB.Connection
  2.   Dim rs As ADODB.Recordset
  3.  
  4.    'Create a new ADO Connection object
  5.   Set cn = New ADODB.Connection
  6.  
  7.    'Use the Access 10 and SQL Server OLEDB providers to
  8.    'open the Connection
  9.    'You will need to replace MySQLServer with the name
  10.    'of a valid SQL Server
  11.    With cn
  12.       .Provider = "Microsoft.Access.OLEDB.10.0"
  13.       .Properties("Data Provider").Value = "SQLOLEDB"
  14.       .Properties("Data Source").Value = "SERVER"
  15.       .Properties("User ID").Value = "username"
  16.       .Properties("Password").Value = "password"
  17.       .Open
  18.    End With
  19.  
  20.    'Create an instance of the ADO Recordset class, and
  21.    'set its properties
  22.    'Set rs = New ADODB.Recordset
  23.    With rs
  24.       Set .ActiveConnection = cn
  25.       .Source = "SELECT field1, field2 FROM table WHERE field1=1234 order by pk01;"
  26.       .LockType = adLockOptimistic
  27.       .CursorType = adOpenKeyset
  28.       .Open
  29.    End With
  30.  
  31.    'Set the form's Recordset property to the ADO recordset
  32.    Set Me.Recordset = rs
  33.    Set rs = Nothing
  34.    Set cn = Nothing
  35.  
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)?
Expand|Select|Wrap|Line Numbers
  1. 'Set rs = New ADODB.Recordset
May 16 '07 #3
matthooper
37 New Member
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
May 16 '07 #4
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?
May 16 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2227
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 <%
2
4341
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
2
1429
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(); ...
11
2432
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...
4
9735
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
2
1860
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
20
3281
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 ? ...
8
4250
Dököll
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")
0
8604
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
9160
Oralloy
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...
0
9029
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
8897
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
8862
tracyyun
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...
1
6521
isladogs
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
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
3
2002
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.