Problems connecting to an Access MDB file through PowerShell - ms-access

I am attempting to connect to an Access 2000 database file (*.mdb), but I am having just a tad few issues. Here is the screenplay thus far,
1) Googled how to connect to a database using powershell which resulted in the following as a source code baseline.
$adOpenStatic = 3
$adLockOptimistic = 3
$objConnection = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$objConnection.Open("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = c:\scripts\sample.mdb")
$objRecordset.Open("Select * from TotalSales", $objConnection,$adOpenStatic,$adLockOptimistic)
$objRecordset.MoveFirst()
do
{ $objRecordset.Fields.Item("EmployeeName").Value; $objRecordset.MoveNext() }
until ($objRecordset.EOF -eq $True)
$objRecordset.Close()
$objConnection.Close()
2) I substituted the Data Source for the fully qualified path of my database then was presented with the following.
Exception calling "Open" with "5" argument(s): "Record(s) cannot be read; no read permission on 'RqRequirements'."
At :line:23 char:18
+ $objRecordset.Open <<<< ("Select * from RqRequirements", $objConnectionCsdscDB,$adOpenStatic,$adLockOptimistic)
3) Since this is a Rational RequisitePro database I almost never need to edit the database directly, but come to find out if we need to edit the database direct we need to issue the following command as a link on the Windows Desktop:
"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" /wrkgrp C:\Program Files\Rational\RequisitePro\bin\rqprodb.mda" /user "xxxxxxx" /pwd "yyyyy"
4) Taking the script listed above and changing it slightly I have the following:
$adOpenStatic = 3
$adLockOptimistic = 3
$objConnectionRqProDB = New-Object -comobject ADODB.Connection
$objConnectionCsdscDB = New-Object -comobject ADODB.Connection
$objRecordset = New-Object -comobject ADODB.Recordset
$cnnStringRqProDB = "Provider = Microsoft.Jet.OLEDB.4.0;" +
"Data Source = C:\\Program Files\\Rational\\RequisitePro\\bin\\rqprodb.mda;" +
"UID=requisite admin;" +
"PWD=multiuser"
$cnnStringCsdscDB = "Provider = Microsoft.Jet.OLEDB.4.0;" +
"Data Source = J:\\TestPowerShell\\Rational.MDB"
$objConnectionRqProDB.Connectionstring = $cnnStringRqProDB
$objConnectionRqProDB.Open()
$objConnectionCsdscDB.Connectionstring = $cnnStringCsdscDB
$objConnectionCsdscDB.Open()
$objRecordset.Open("Select * from RqRequirements", $objConnectionCsdscDB,$adOpenStatic,$adLockOptimistic)
$objRecordset.Close()
$objConnection.Close()
5) When I run this script I get the following error:
Exception calling "Open" with "4" argument(s): "Could not find installable ISAM."
At :line:17 char:26
+ $objConnectionRqProDB.Open <<<< ()
6) I did some searching and found the following link, http://support.microsoft.com/kb/209805, and I checked the registry and the entry is present for
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Paradox
win32=C:\WINDOWS\system32\mspbde40.dll
this file is located in %SYSTEM32%\
Note, I do not have Access installed on my system (could this be an underlying problem? I am not sure, but I wouldn't think so since I am using the ADO)
Questions:
1) How do I include the "/wrkgrp" option in the connection string in the script?
2) Assuming the lack of the "/wrkgrp" option in the connection string is not my problem what might be issue?
3) Does Access need to be installed on the system in order for this to work?
Thanks, Mark

You shouldn't need Access installed.
You are trying to open the workgroup database (mdw) separately - don't do that.
You need to specify the workgroup database in the connect string
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;
Jet OLEDB:System Database=system.mdw;User ID=myUsername;Password=myPassword;
So in your case, use the following:
$cnnStringRqProDB = "Provider = Microsoft.Jet.OLEDB.4.0;" +
"Data Source = J:\\TestPowerShell\\Rational.MDB;" +
"Jet OLEDB:System Database = C:\\Program Files\\Rational\\RequisitePro\\bin\\rqprodb.mda;" +
"User ID=requisite admin;" +
"Password=multiuser"
$objConnectionCsdscDB.Connectionstring = $cnnStringCsdscDB
$objConnectionCsdscDB.Open()

Related

df.to_sql with AS400

i want to put a Panda Dataframe to a IBM i Series / AS400. I already researched a much, but now I am stuck.
I already made a lot of queries, where I use pyodbc. For df.to_sql() I should use, as readed on other stacks, sqlalchemy with the ibm_db_sa dialect.
My actual code is:
CONNECTION_STRING = (
"driver={iSeries Access ODBC Driver};"
"System=111.111.111.111;"
"database=TESTDB;"
"uid=USER;"
"pwd=PASSW;"
)
quoted = urllib.parse.quote_plus(CONNECTION_STRING)
engine = create_engine('ibm_db_sa+pyodbc:///?odbc_connect={}'.format(quoted))
create_statement = df.to_sql("TABLETEST", engine, if_exists="append")
the following packages are installed
python 3.9
ibm-db 3.1.3
ibm-db-sa 0.3.7
ibm-db-sa-py3 0.3.1.post1
pandas 1.3.5
pip 22.0.4
setuptools 57.0.0
SQLAlchemy 1.4.39
when I run, i get the following error:
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('42S02', '[42S02] [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0204 - COLUMNS in SYSCAT type *FILE not found. (-204) (SQLPrepare)')
[SQL: SELECT "SYSCAT"."COLUMNS"."COLNAME", "SYSCAT"."COLUMNS"."TYPENAME", "SYSCAT"."COLUMNS"."DEFAULT", "SYSCAT"."COLUMNS"."NULLS", "SYSCAT"."COLUMNS"."LENGTH", "SYSCAT"."COLUMNS"."SCALE", "SYSCAT"."COLUMNS"."IDENTITY", "SYSCAT"."COLUMNS"."GENERATED"
FROM "SYSCAT"."COLUMNS"
WHERE "SYSCAT"."COLUMNS"."TABSCHEMA" = ? AND "SYSCAT"."COLUMNS"."TABNAME" = ? ORDER BY "SYSCAT"."COLUMNS"."COLNO"]
[parameters: ('USER', 'TABLETEST')]
(Background on this error at: https://sqlalche.me/e/14/f405)
I think, the dialect could be wrong, because the parameters are the username and the table for the ODBC connection?
AND: I am not really sure, whats the difference between ibm_db_sa and ibm_db?
I tried a few days again, before someone is trying to do this via sqlalchemy should do it via pyodbc.
Here is my working example
refering the df_to_sql_bulk_insert function to this
(and now I am currently using my system-DSN):
def df_to_sql_bulk_insert(df: pd.DataFrame, table: str, **kwargs) -> str:
df = df.copy().assign(**kwargs)
columns = ", ".join(df.columns)
tuples = map(str, df.itertuples(index=False, name=None))
values = re.sub(r"(?<=\W)(nan|None)(?=\W)", "NULL", (",\n" + " " * 7).join(tuples))
return f"INSERT INTO {table} ({columns})\nVALUES {values}"
cnxn = pyodbc.connect("DSN=XXX")
cursor = cnxn.cursor()
sqlstr = df_to_sql_bulk_insert(df,"DBXXX.TBLXXX")
cursor.execute(sqlstr)
cnxn.commit()

Microsoft SQL Server Reporting Services 2017 registry

Did registry paths change for the Microsoft SQL Server Reporting Services 2017?
Before we were able to locate instance name here:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS\MSSQLSERVER
But now in 2017 MSSQLSERVER is missing and it has SSRS instead.
Based on this article it should be still under MSSQLSERVER but it's not. Did we missed some installation setting that caused this or this is default standard behavior now?
Because Reporting Services is now a separate installation, it installs as a named instance SSRS. This is a change from previous versions where Reporting Services was part of SQL Server setup.
I would suggest using WMI queries to obtain the necessary information (example below using PowerShell). Notice that the v14 refers to the 2017 release.
$wmiName = (Get-WmiObject –namespace root\Microsoft\SqlServer\ReportServer –class __Namespace).Name
$rsConfig = Get-WmiObject –namespace "root\Microsoft\SqlServer\ReportServer\$wmiName\v14\Admin" -class MSReportServer_ConfigurationSetting
I know this post is old but I had the same problem in my company to find information from RS 2017 and found no place that reported the right location so I wanted to post here!
My friend (Paulo Henrique Rodrigues Orind) and I found a place where you can get all the information about the RS 2017 and I hope the RS 2019 is the same.
1) By PowerShell + WMI:
Get-WmiObject -namespace "root\Microsoft\SqlServer\ReportServer\RS_SSRS\V14" -class MSReportServer_Instance | Select-Object -Property EditionName, Version, InstanceName
Image-powerShellCommand
2) By C# + WMI (Do you will need to import the System.Management.dll)
using System;
using System.Management;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope("Root\\Microsoft\\SqlServer\\ReportServer\\RS_SSRS\\V14", options);
scope.Connect();
//Query system for Operating System information
ObjectQuery query = new ObjectQuery("SELECT * FROM MSReportServer_Instance");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
// Display the remote computer information
Console.WriteLine("EditionName : {0}", m["EditionName"]);
Console.WriteLine("EditionID : {0}", m["EditionID"]);
Console.WriteLine("InstanceID : {0}", m["InstanceID"]);
Console.WriteLine("InstanceName : {0}", m["InstanceName"]);
Console.WriteLine("Version : {0}", m["Version"]);
}
Console.ReadKey();
}
}
}
Image-CsharpCode-Wmi
3) WMI:
wmi_1
wmi_2
wmi_3
wmi_4
Opening the WMI:
Namespace: Root >> Microsoft >> SqlServer >> ReportServer >> RS_SSRS >> V14
Class: MSReportServer_Instance
I hope I have helped with something

How to use sparklyr spark_write_jdbc to connect to MySql

spark_write_jdbc(members_df,
name = "Mbrs",
options = list(
url = paste0("jdbc:mysql://",mysql_host,":",mysql_port,"/",dbname),
user = mysql_user,
password = mysql_password),
mode = "append")
Results in the following exception:
Error: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
The .jar file is in a folder on the server where RStudio is running, config details below. We're able to access MySql via the RMySql package so MySql is working and accessible.
config$`spark.sparklyr.shell.driver-class-path` <- "/dev/shm/temp/mysql-connector-java-5.1.44-bin.jar"
Even if the question is different, I think the answer still applies also to this:
How to use a predicate while reading from JDBC connection?
Code to connect to JDBC MySQL through sparklyr (I made some slight changes to simplify the code a bit, written by Jake Russ)
library(sparklyr)
library(dplyr)
config <- spark_config()
#config$`sparklyr.shell.driver-class-path` <- "E:\\spark232_hadoop27\\jars\\mysql-connector-java-5.1.47-bin.jar"
#in my case, using RStudio and Sparkly this seemed to be optional
sc <- spark_connect(master = "local")
db_tbl <- spark_read_jdbc(sc,
name = "table_name",
options = list(url = "jdbc:mysql://localhost:3306/schema_name",
user = "root",
password = "password",
dbtable = "table_name"))

R package monitoR error on dbUploadTemplate [pkg-monitor]

I'm using the R package monitoR and getting an error message that I can't figure out.
I'm trying to upload a correlation template list ("bithTemps") to a MySQL database ("noh") using the dbUploadTemplate command.
dbUploadTemplate(templates = bithTemps,
uid = "root",
pwd = "****",
db.name = "noh",
analyst = 1,
locationID = "2",
date.recorded = "2017/09/07",
recording.equip = "Unknown",
species.code = "BITH",
type = "COR")
This returns:
Error: $ operator is invalid for atomic vectors
I have confirmed the ODBC connection is working, that the template list is functional (i.e., it works when called to other arguments in the package), and that the SQL database has the required entries for analyst, location, and species code.
It seems that this error was actually triggered by a non-functional ODBC connection. This part of the dbUploadTemplate function
species <- RODBC::sqlQuery(dbCon, paste("SELECT `pkSpeciesID`, `fldSpeciesCode` FROM `tblSpecies` WHERE `fldSpeciesCode` = '",
paste(species.code, sep = "", collapse = "' OR `fldSpeciesCode` = '"),
"'", sep = ""))
queries a table in the SQL database and returns an object called 'species'. If the query fails (e.g., because RODBC can't connect) than 'species' is empty, and the following operation
speciesID <- NULL
for (i in 1:length(species.code)) {
speciesID[i] <- species$pkSpeciesID[species$fldSpeciesCode ==
species.code[i]]
}
triggers the error. Fixing the ODBC connection resolves the error.

Connecting from rails to an external azure database to import data

Hello Stackoverflow members,
I need to import data from an external database which is an azure database. And i am getting the following error: TinyTds::Error: USE statement is not supported to switch between databases. Use a new connection to connect to a different database.
class Exact
require 'tiny_tds'
def connect
dbadmin = ""
password = "!"
server = ""
database = ""
a = true
client=TinyTds::Client.new(:username=>'', :password=> password, :dataserver=> server , :port=>1433, :database=>database, :azure=> 'true')
puts "connecting"
results = client.execute("select * from table")
puts "results opgehaald"
puts results.first
client.close
puts "client is closed"
end
end
I think i need to open a new connection to connect to the database but i am having problems figuring this out. Could anyone point me in the right direction or assist me with the problems i am having.
Kind regards,
Yoeri Huitema
I fixed the issue as described in this thread: https://github.com/rails-sqlserver/tiny_tds/issues/249
client=TinyTds::Client.new(:username=>'', :password=> password, :dataserver=> server , :port=>1433, :database=>database, :azure=> 'true')
should have been
client=TinyTds::Client.new(:username=>'', :password=> password, :dataserver=> server , :port=>1433, :database=>database, :azure=> TRUE)