I am using MySql 5.0. I using Mupliple datareader in same connection i get error message. Is possible to use multiple Datareader in same connection?
I using Mysql Connection is
MySqlConn.ConnectionString = "SERVER=" & gServerName & ";DATABASE=" & DBname & ";user=" & gUserName & ";password=" & gPassword & ";MultipleActiveResultSets=True"
MySqlConn.Open()
Please Help Me
The DataReader usually (excluding SQL Server 2005+) requires a connection all to itself while it is Executing. Until the DataReader's Close method is called, the connection cannot be used by anything else including another DataReader.
However, you can use the DataReader's NextResult method to let it process multiple sets of records one after another.
Related
I have some VBA code in Outlook that runs a SQL query and populates a userform I designed. This code was previously running fine on one PC, then I was issued a new laptop and I copied the outlook VBA module directly over.
When I try to run, I just get an error "Compile Error: Can't find project or library" and the text "adOpenStatic" in the RS.open statement is highlighted. Previously, I had seen the same error if my SQL query was bad or the driver was missing, but I double checked both. I copied the EXACT code into an excel VBA module and it ran as expected.
The only other difference I can see is that I went from Outlook 2019 to Office 365 for Enterprise.
Dim server, database, login_user, password, port As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
server = "dummy"
database = "dummy"
login_user = "dummy"
password = "dummy"
port = "dummy"
Set cn = New ADODB.Connection
cn.ConnectionString = "DRIVER={MySQL ODBC 8.0 ANSI Driver};Provider=MSDASQL;" & "SERVER=" & server & ";" & " DATABASE=" & database & ";" & "UID=" & login_user & ";PWD=" & password & "; OPTION=3; PORT=" & port & ";Connect Timeout=20;"
'open the connection
cn.Open
Set rs = New ADODB.Recordset
strSQL = "SELECT * FROM quote WHERE id = 1505"
rs.Open strSQL, cn, adOpenStatic
With rs
Do Until .EOF
'parse out relevant project information
rs.MoveNext
Loop
End With
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
I can run the exact query in MySQL workbench, and it works as expected. The fact that the identical code can run in Excel without issue tells me there is perhaps a syntax difference in Outlook that I am unaware of? Anyone else have ideas?
NOTE, if it wasn't already obvious, I am omitting my database details with "Dummy", but the real code has the correct strings.
This code was previously running fine on one PC, then I was issued a new laptop and I copied the outlook VBA module directly over.
You need to re-add all COM references you had on the old machine.
From the Tools menu, choose References to display the References dialog box.
The References dialog box shows all object libraries registered with the operating system. Scroll through the list for the application whose object library you want to reference. If the application isn't listed, you can use the Browse button to search for object libraries (*.olb and .tlb) or executable files (.exe and *.dll on Windows). References whose check boxes are selected are used by your project; those that aren't selected are not used, but can be added.
Go to the VBA Editor, and choose Tools-References; and tick the box next to 'Microsoft ActiveX Data Objects' (the latest version). It should compile ok now.
I'm trying to get some information from a mysql database to a report in access. But I can't figure out how to get the information there since I'm using DAO connections in vba and cant use linked tables.
I've tried storing the information into a string from the form that I already have the information at through a DAO connection directly to mysql db with no luck.
Private Sub Command67_Click()
DoCmd.Save
DoCmd.GoToRecord , , acNewRec
Me.Label39.Visible = True
Dim strWhere As String
strWhere = "[ID] = " & Me.[Id]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End Sub
I use preview in that code to see some result but what I would like to do is print directly to the printer since this is a client turn receipt i need those to print fast.
Again I can't use linked tables.
After investigating on your former questions (some should be linked to that question), I see the problem. You don't link the MySQL-Tables what would make things easier for you.
But you can still use queries! Just put your connection string (maybeGlobales.ConnStringin former questions) in the queriesODBC Connection Stringin query design->properties. That makes the query a passthrough-query that is passed to MySQL-Server directly, not using MDAC.
Just set the reportsRecordSourceto the name of the query.
You can also build the query in VBA, but you can't use a temporary QueryDef("") as you can't set the Reports-Recordset, so use a non temp one.
Example (assumes there is a QueryDef named QueryForReport):
Sub EditQueryDefPassthrough()
With CurrentDb.QueryDefs("QueryForReport")
.Connect = "ODBC;Driver={MySQL ODBC 5.3 ANSI Driver};" _
& "Server=YourServerName;" _
& "Database=YourDatabaseName;" _
& "User=YourMysqlUserName;" _
& "Password=MysqlPwdForUser;" _
& "Option=3;" ' adapt this to your MySQL ODBC Driver Version and server settings
.SQL = "SELECT `Field` FROM `TABLE` LIMIT 1,1;" 'put SQL here (MySQL SQL Dialect, not MS-Access!). You can't use Access functions here (like Replace(), ..., but those of MySQL like Concat().
End With
End Sub
The QueryDef needs to be set before the Report_Load Event, but in Report_Open should be sufficent (e.g. if you want to use OpenArgs for building the SQL-String)
I'm using vb.net and mysql( from a shared hosting) with the following code
Public conn As OdbcConnection
Public da As OdbcDataAdapter
Public ds As DataSet
Public dr As OdbcDataReader
Public cmd As OdbcCommand
Public MysqlConn As MySqlConnection
Public xc As MySqlCommand
Public xd As MySqlDataAdapter
Public serv As String, user As String, pass As String, db As String
Sub connect()
serv = "xyz.com"
user = "abc"
pass = "mypasword"
db = "mydb"
MysqlConn = New MySqlConnection()
MysqlConn.ConnectionString = "server=" & serv & ";" & "UserID=" & user & ";" & "password=" & pass & ";" & "database=" & db & ";Character Set=utf8;"
Try
MysqlConn.Open()
MysqlConn.Close()
Catch myerror As Exception
MsgBox("Connection Error")
End Try
End Sub
Now any select, insert or update action takes more that 5 seconds and freezes the whole application. But my client wants it faster. How can I speed it up? is that the hosting or mysql or connection method - which is to upgrade or alter with other to make it faster?
Thanks
India:Canada -- 140ms seems reasonable. This means that every query sent to the server will take at least that long.
As for the "5 seconds"... Turn on the "General log" for a short while and run the app. Then look through the log. You may find that vb.net is injecting some extra commands, possibly in front of each query you run. This would further slow down your application. If that is the case, abandon vb.net, and be suspicious of any other 3rd party software.
I hope you are doing only one "connection" for an entire session?
Aside from that, the best thing to consider doing is to write Stored Routines (Procedures, Functions, Triggers, etc) whenever you need to perform more than one query in a row. That way, you can issue one query instead of multiple SQL statements, thereby fewer roundtrips.
I'm running a Pivotal application (5.9) and have a server process which always crashes (MS SQL error 1206).
I have a Pivotal "active form" with an update button, which, when clicked, calls a server process (VB 6 custom DLL)
This custom DLL :
retrieves the list of all users who can use the Pivotal application ("users" standard table) by using the Pivotal API, and then creates its own connection to another database using a connection string)
For each users, it constructs and run the a query :
strSql = select SUM(stoResourceSize) totalResourceSize from " & dbName &
".dbo.Resource Where StorageID = 3 and XptDestinationAddress like "
strSql = strSql & "'%" & userName & "%'"
The connection string used to run the query is the following :
strConnect = "Driver={SQL Server};" & _
"Server=" & SatteliteName & ";" & _
"UID=" & SyncStreamDBName & ";" & _
"Trusted_Connection=Yes"
It works fine but the query crashes after about 80 users processed, with error 1206 and SQLState = 37000
I can reproduce that problem every single time. At a given time, this query will crash.
I have added a lot of trace and the last query works fine if I run it on the server "by hand".
It doesn't crash on the same user every time, it looks like it is random. Besides, in the application there exists another server procedure which can run the same query but only for one user. That one will run fine and never crash.
I have also tried to enabled ODBC trace but it wouldn't give me any useful information.
I'm pretty confidnet it is a connection or configuration problem but I don't know what.
This problem is reproducible both in developpment and testing environnments.
edit: actually it seems that my server process can crash at various points, not necessarily when executing that request.
It seems to crash when I open ADODB recordsets (of course, before touching any recordset, I verify that both EOF and BOF are false, and they are).
I have a few data sources in access that I need to connect to programatically to do things with behind the scenes and keep visibility away from users.
Said datasource has a password 'pass' as I'm going to call it here. Using this connection method I get an error attempting to use the open method
Dim conn as ADODB.Connection
Set ROBBERS.conn = New ADODB.Connection
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=\\pep-home\projects\billing\autobilling\DPBilling2.mdb;" _
& "Jet OLEDB:Database Password=pass;", "admin", "pass"
"Cannot start your application. The workgroup information file is missing or opened exclusively by another user."
Due to planning to move into 2007, we are not using nor have ever used a workgroup identification file through access. The database password on the data source was set through the Set Databa Password which had to be done on an exclusive open.
Ive spent a good while changing around my connection options, where to put the passwords etc and either cannot find the right format, or (why I'm asking here) I think there may be some other unknown that I must setup to do this. Anyone out there got some useful information?
Your connection string seems to be incorrect. Try:
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=\\pep-home\projects\billing\autobilling\DPBilling2.mdb;" _
& "Jet OLEDB:Database Password=MyDbPassword;"
-- http://www.connectionstrings.com/access