DBHandle function always fails in PB12.net - database-connection

I have migrated a project from PowerBuilder 12 classic to Powerbuilder 12.net using PFC. Even though in PB12 the connection to the database is successful that is not true for PB12.net.
I have been debugging for the problem and the DBHandle function in of_IsConnected of pfc_n_tr returns false. In PB12 classic this returns true. I have made a database profile which connects successfully though.
This is the code which checks for a successful connection:
if this.DBHandle() = 0 then
return false
else
return true
end if
I added connect using sqlca; to see the problem before the check but I got:
Transaction already connected in SQLErrText.
What might be the problem?

So the problem was in DB parameters connection for sql server 2008.
I changed the DBMS variable to "SNC SQL Native Client(OLE DB)" and added the Provider='SQLNCLI10' to the DBParm string.

Related

Why is wifi.sta nil even after wifi.setmode(wifi.STATIONAP)?

EDIT: what I'm trying to do is essentially configure the station after
the softap is running a TCP server.
I get a panic error for wifi.sta being nil when I call wifi.sta.config(station_cfg) even after I configured it properly before.
When I do:
function connectHib()
wifi.setmode(wifi.STATIONAP)
[AP config here]
station_cfg={}
station_cfg.ssid = ""
station_cfg.pwd = ""
station_cfg.save = false
station_cfg.auto = false
wifi.sta.config(station_cfg)
end
It works fine, but when I call it, then start a server with srv=net.createServer(net.TCP) and then call the following function:
function validateSTA()
station_cfg={}
station_cfg.ssid = _G.wifi
station_cfg.pwd = _G.senha
station_cfg.save = false
station_cfg.auto = false
wifi.sta.config(station_cfg) -- this creates an error
wifi.sta.connect()
end
It gives me a PANIC error on the commented line. I'm just trying to reconfigure the STATION module only and then tell it to connect so I can validate the conection.
I'm using:
NodeMCU custom build by frightanic.com
branch: master
commit: 67027c0d05f7e8d1b97104e05a3715f6ebc8d07f
SSL: false
modules: adc,file,gpio,net,node,pwm,sjson,tmr,uart,wifi
build created on 2018-04-16 13:55
powered by Lua 5.1.4 on SDK 2.2.1(cfd48f3)
What bugs me is why it seems like it has not been "declared" before, but it works on the first function... I thought wifi. was global like _G. variables.
It also works if I call the functions separately on the ESPlorer command line on an ESP without my init.lua.
I also tried the debug firmware and the only odd thing I saw poping up was wifi_event_monitor_handle_event_cb that is called every 4 secconds or so.
Thanks guys, any help is apreciated as I'm stuck about a week now.
Like many other script languages, lua doesn't have declarations, only assignments.
You should perform checks what is wifi's value during the first and the second calls. It seems that at first you are using it as a table, and in the second function you try to use it as a string in the station_cfg.ssid = _G.wifi.
Or the reason is that global variables are not "like _G", they're stored in _G.

Ruby on rails - Get data froma a remote DB without an API

I'm trying to get data in a remote database from my app. I can do it with
ActiveRecord::Base.establish_connection({
'adapter'=>'postgresql',
'host'=> host_db,
'port'=> port,
'username'=> username_db,
'password'=> password_db,
'database'=> name_db
})
data = ActiveRecord::Base.connection.execute(tiraSQL)
ActiveRecord::Base.establish_connection ENV['DATABASE']
But after the last line ActiveRecord::Base.establish_connection ENV['DATABASE'] all my tables become empty.
Is there any way that after the line I mentioned above the previos data in my model persists in a test enviorement (rspec)?
or
i can get the data from a database in other host but whitout changing my current ActiveRecord::Base connection.
Thnx in advance guys
Rails only keeps one database connection open at a time on ActiveRecord like that... So when you establish the connection, you are completely overwriting the old connection (to your local database).
You'll probably want to save the old connection somewhere, and return it after you connect to the new database... Then store the new connection somewhere. eg
old_connection = ActiveRecord::Base.connection
new_connection = ActiveRecord::Base.establish_connection({
'adapter'=>'postgresql',
'host'=> host_db,
'port'=> port,
'username'=> username_db,
'password'=> password_db,
'database'=> name_db
})
data = new_connection.execute(tiraSQL)
ActiveRecord::Base.connection = old_connection
Note: I have not personally tested this code - you may well need to do something else to make it actually work.

Is this a bug: stored procedure runs fine without parameters, causes error when parameters are added?

I have a stored procedure created in MySQL DB. This database is accessed as linked server through Microsoft SQL Server 2012 using Microsoft SQL Server Management Studio. The provider selected while creating linked server is "Microsoft OLE DB Provider for ODBC Drivers".
When I run following as text from Report builder 3.0 it runs fine and fetch data.
EXEC('CALL storedProcedureName(''string1'', ''string2'', ''string3'')') AT LinkedServerName;
But when I try to replace string1, string2, string3 with parameter name parameter1, parameter2, parameter3 as:
EXEC('CALL storedProcedureName(#parameter1, #parameter2, #parameter3)') AT LinkedServerName;
I get error:
Could not execute statement on remote server 'LinkedServerName'.
(Microsoft SQL Server, Error: 7215)
And when I try:
EXEC('CALL storedProcedureName('#parameter1', '#parameter2', '#parameter3')') AT LinkedServerName;
I get the prompt to enter values for parameter1, parameter2, parameter3. But when I enter the values and click ok, I get error:
Incorrect syntax near '#parameter1'. (Microsoft SQL Server, Error: 102)
Question: Am I missing something in syntax or is this a bug?
The linked server has:
"RPC" and "RPC out" set to True.
And the OLEDB provider has:
Enabled allow inprocess
Enabled dynamic parameter
I believe you have to call it like the below. So params become strings wrapped in single quotes:
EXEC('CALL storedProcedureName('''+#parameter1+''', '''+#parameter2+''', '''+#parameter3+''')') AT LinkedServerName;
I know this is an older question but the accepted answer is open to SQL Injection and I think it's important to offer a more secure method.
You really want to use a parameterized query
EXEC('CALL storedProcedureName(?,?,?)',#parameter1, #parameter2, #parameter3) AT LinkedServerName;
I know this works for oracle and it should work for MySql as well.

Delphi TClientDataSet "Trying to modify read-only field" error in SQL Server 2008, OK in 2000

Embarcadero® Delphi® 2010 Version 14.0.3593.25826
We are attempting to move a database from SQL Server 2000 to SQL Server 2008. I have a TClientDataSet that is loaded with a SELECT that includes a computed column, i.e., "SELECT Comp_Col = Column1 + ' ' + Column2...".
Running against an SQL Server 2000 database, I can modify the value of the column in the TClientDataSet using the following code:
ClientDataSet1.Edit();
ClientDataSet1.FieldByName('Comp_Col').ReadOnly := false;
ClientDataSet1.FieldByName('Comp_Col').Value := 'MODIFIED';
ClientDataSet1.FieldByName('Comp_Col'').ReadOnly := true;
ClientDataSet1.Post(); // <-- EXCEPTION in 2008
Running against an SQL Server 2008 database, though, I get a "Trying to modify read-only field" error when executing .Post().
I have tried also setting .ProviderFlags = '[]' for the column (in addition to .ReadOnly = false) in the above code, but still get the error. I have also tried setting .ReadOnly = false and .ProviderFlags = '[]' at design-time via the IDE, but this does not help either.
Anybody know how to set a computed column in a TClientDataSet when running against an SQL Server 2008 database?
Thanks!
* UPDATE: ANSWERED *
I discovered the problem--or at least a workaround...
I WAS setting .ReadOnly = false for the column in the TClientDataSet object. This worked with SQL Server 2000 but not with SQL Server 2008.
If I set .ReadOnly = false in for the column instead in the TADOQuery object that is serving as the provider, then I am able to set the value of the computed column in the TClientDataSet object at run-time.
Not ideal for me since this was implemented in a generic function for TClientDataSet objects (that didn't anything about the provider), but it will have to do for now.
I discovered the problem--or at least a workaround . . .
I WAS setting .ReadOnly = false for the column in the TClientDataSet object. This worked with SQL Server 2000 but not with SQL Server 2008.
If I set .ReadOnly = false for the column instead in the TADOQuery object that is serving as the provider, then I am able to set the value of the computed column in the TClientDataSet object at run-time.
Not ideal for me since this was implemented in a generic function for TClientDataSet objects (that didn't anything about the provider), but it will have to do for now.
My experience shows that the creation of ClientDataSet fields by calling TClientDataSet.CreaeteDataSet initially without ReadOnly flags solves the problem. After opening ClientDataSet fields' ReadOnly flags can be returned to their seats for the proper functioning of data-aware controls.

Multiple-step OLE DB operation generated errors [duplicate]

Dim NorthWindOledbConnection As String = "Provider=SQLOLEDB;DataSOurce=SARAN-PC\SQLEXPRESS;Integrated Security=ssp1;InitialCatalog=Sara"
Dim rs As New ADODB.Recordset()
rs.Open("select * from SecUserPassword", NorthWindOledbConnection, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic)
i tried to run this above code in visual studio 2008 - it shows the following error:
"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done"
Firstly, don't use ADO in VB.NET. Use ADO.NET.
Other than that, create a proper Connection object instead of passing around a string.
And fix your connection string. It's SSPI, not SSP1. And it's Data Source, not DataSOurce. And it's Initial Catalog, not InitialCatalog.
You are using a very very very old way to access a Database that has been used with Visual Basic 6 and older.
Check to use ADO.NET instead of old ADO. For example you can use this code that is "similar" to the code you are using (but is not the best way to access the data on VS2008)
OleDbConnection con= New OleDbConnection( **Your Connection String** )
con.Open()
Dim command As OleDbCommand = New OleDbCommand("select * from SecUserPassword", con)
sqlCommand .CommandType = CommandType.Text
Dim reader As OleDbDataReader = TheCommand.ExecuteReader()
While reader.Read()
System.Console.Write(reader(** Your Table Field Name** ).ToString())
End While
con.Close()
To view how to create a correct connection String see the site http://www.connectionstrings.com/
If you want to access to an SQL Server database also you can use the SQLClient namespace instead the OleDb. For example System.Data.SqlClient.SqlConnection instead the OleDbConnection to provide better performance for SQL Server
The link below is an article that gives a great breakdown of the 6 scenarios this error message can occur:
Scenario 1 - Error occurs when trying to insert data into a database
Scenario 2 - Error occurs when trying to open an ADO connection
Scenario 3 - Error occurs inserting data into Access, where a fieldname has a space
Scenario 4 - Error occurs inserting data into Access, when using adLockBatchOptimistic
Scenario 5 - Error occurs inserting data into Access, when using Jet.OLEDB.3.51 or ODBC driver (not Jet.OLEDB.4.0)
Scenario 6 - Error occurs when using a Command object and Parameters
http://www.adopenstatic.com/faq/80040e21.asp
Hope it may help others that may be facing the same issue.

Resources