VBA odbc connection accessing a single library only - excel

I have successfully connected to an as400 server. But whenever i execute an sql statement
select * from nosd0
It doesn't work, because nosd0 is in lib1/fil1(nosd0)
it gives an error saying nosd0 is not in lib2.
When I execute the query on STRSQL on as400 it works fine.
I tried creating an alias and it's malfunctioning. Please I really need some help on this one
Alias is working, I am accessing the wrong file.

Ok I figured out the problem, this will also help all those who wants to connect to their AS400 iSeries using VBA. ;)
My problem above is that when I try my Query on the box, it accesses lib1/nosd0, and in VBA, I was trying to get lib2/fil1(nosd0) which is a description of the table nosdo itself. The simple solution is to query
select * from lib1.nosd0
More on that when connecting to an AS400 iSeries using ODBC, there is a parameter called DBQ
Connection String Parameters
My final connection string would be.
ConnectString = "Driver={ISeries Access ODBC Driver};System=" & DCServer(I) & ";Uid=--;Pwd=--;NAM=0;DBQ=lib1,*ALL;"

Related

Problem sending datas by Excel-VBA to PostgressSQL: [ODBC driver manager] data source name not found and no default driver specified

I need help with a task.
I have a VBA code at Excel to send some datas for PostgressSQL.
These days I reinstalled my Excel, but now, when I try to send the data the VBA presents the message below and the data is not include in my database:
"[ODBC driver manager] data source name not found and no default driver specified"
The debug highlight that the problem is in Conexao.Open. Below is part of the code with this:
Sub Conectar_BD()
Set Conexao = New ADODB.Connection
Conexao.ConnectionString = "DRIVER={PostgreSQL ANSI(x64)}; SERVER=localhost; DATABASE=yyyy; UID=marcel; PASSWORD=xxx;"
Conexao.Open
End Sub
Looking for some answers I found the explanation that I have to install the driver, but I´m not sure about how I could do that.
However, researching more I discovered a tutorial teaching how to connect the driver by admnistrative tool in the panel of control of windows called Datasource ODBC.
Following the instructions, when I added PostgreSQL ANSI(x64), that is there and put the credentials of my database, the conecction was sucessfully but the excel continue to present the same message.
Anyway, I don´t know how to fix this problem yet.
Anyone can help me?

vb.net Cannot update. Getting error "Database or object is read-only." when just trying to READ from excel file

I'm more than willing to accept other suggestions on ways to accomplish what I want to do. I am trying to read some lines from an excel spreadsheet that the user uploads to my application. The web server where this will eventually reside does not have excel installed on it, which makes referencing things like Microsoft.Office.Interop.Excel.dll in my project impossible. So I've been looking for ways to read the excel file so that will work with this situation. The best way I've found so far is to use Microsoft.Jet.OLEDB.4.0 to connect to the excel file like a datasource. Here is a small snippet of I've put together so far:
Dim excelFileName As String = "C:\\Import\\K12Mercury.xlsx"
Dim conn As New OleDb.OleDbConnection(String.Format("provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & excelFileName & "; Extended Properties='Excel 8.0;HDR=YES;'"))
conn.Open()
The program fails on the conn.Open() line with the error:
cannot update. database or object is read-only
I don't know why this is happening or if this is even the best route to use to be able to read from an excel file in an environment where excel is not installed. Will someone please help me? Thanks in advance.

SqlState 24000, Invalid cursor state

I am trying to help one of our developers resolve an Azure SQL DB error. He has attempted to run a script, connecting using sqlcmd and (I presume) ODBC. It seems no matter what he does he receives the error message "SqlState 24000, Invalid cursor state".
His script consists of roughly 80 "insert into table where not exists sub-select" statements. Some of the sub-selects return zero records.
I read this post which is admittedly almost a year old now. The short version seems to be "this is a known Azure SQL DB bug".
sqlcmd on Azure SQL Data Warehouse - SqlState 24000, Invalid cursor state after INSERT statement
I know for certain my developer has been able to run these statements previously. Is that just the nature of a bug - sometimes it occurs and sometimes it doesn't? Does he need to use a different ODBC driver? Any other suggestions?
Please make sure you are using ODBC driver 13.1 or later. You can download it from here.

Disabling OID in AWS Redshift

I'm running into an ODBC issue with OIDS from Redshift
I have to build dynamic reports in excel using an ODBC connection and it says it can't find the Oid column.
I'm waiting to see if the DBA can change the default settings but every PostgreSQL command to disable OIDS doesn't work in Redshift. Suggestions? Please, no comments on Excel as reporting tool, it's all I've got at the moment.
I've tried the following to no avail:
CREATE TABLE (
...
) WITHOUT OIDS;
CREATE TABLE (
...
) WITH ( OIDS = FALSE );
alter table [tablename] SET WITHOUT OIDS;
We had the exact same problem and we fixed it by changing the way Excel setup the connection to AWS Redshift. Instead of creating a connection From Microsoft Query, we did it From Data Connection Wizard:
By the way, this allow you to see the connection string (which by default includes FAKEOIDINDEX=0;SHOWOIDCOLUMN=0).
PS: More informations on what are OID and why Excel (Microsoft Query) is using OIDS to handle rows (it's a king of unique row ID). But if you write your own SQL requests, Excel should not annoy you with OIDS..
Hope that helps..

How to update a connection string of an excel file from a script (PS)

We have an excel file which contains a connection to a database to retreive data (with a select statement).
We want to update via a (preferrably powershell) script the connection string of that file to make it query another server instead.
So for exemple :
I have report.xlsx file which connects to server A.
I run update-connection.ps1
And when I open report.xlsx it now connects to server B.
Any idea how we could do that?
Thanks.
It should be fairly easy if you decide (are allowed) to store the connection (server name) in a worksheet. Your VBA code can dynamically build the connection string based on the value of a cell. (I would probably create a named range and use it in the code).
I don't know PowerShell but the code can look something like:
$workbook.Range("Server").Value2 = "PROD_01"
You can make the worksheet hidden if you wish, but it is not a serious security.
You could try automating Excel via PowerShell, as in this article: http://kentfinkle.com/PowershellAndExcel.aspx
If you don't want to automate Excel then you could try using something like ClosedXML in your PowerShell script: http://closedxml.codeplex.com/
You can parse the connectionstring with System.Data.Common.DbConnectionStringBuilder. Check this SO thread:
Powershell regex for connectionStrings?

Resources