Change ODBC in command line (Win. 7) - command-line

I have a set of ODBCs that have to be changed each time I move a computer from one domain to the other. I have move a bunch of them so I am looking for a way to do this with command line to save time. If you know any faster ways of doing this I am open to this also.

You can change from cmd as below.
odbcconf configsysdsn "MySQL ODBC 5.2w Driver"
"DSN=test;SERVER=127.0.0.1;PORT=3306;DATABASE=mdb;UID=root 
Reference: Install An ODBC connection from cmd line

Related

Firebird tools gfix gbak do not launch

Running Firebird 2.5 as a service on a local 64-bit Windows 10 machine.
isql, qli and a bunch of the other tools run just fine.
However when I try an launch gfix, gbak and gstat the window barely opens before disappearing. It does this so quickly nothing is visible.
Any recommendations for dealing with this?
My actual goal at the moment is to change a firebird database from read-only to read-write. Which you can do using gfix http://www.firebirdsql.org/manual/gfix-dbmode.html
If there is some other method to change to read-write I'd happily use it.
The tools gfix, gbak and gstat are command line utilities. They expect certain command line options, and they print their output to the console. If you start them by double-clicking them in explorer, or executing them from the Run prompt, a console is opened, output is written (the usage information as you haven't specified the necessary command line options), and then it exits, closing the console immediately.
This means that if you want to run them and see the output, you need to execute them from the command prompt (cmd), or from a batch-file that has pause at the end.
The fact qli and isql work by opening them from explorer (or run) is because they are interactive tools, waiting for your input.

Permanently set DB2CLP environment variable

I have a problem with DB2CLP environment variable, on Windows 7 64, IBM_client64_V97 (to be connected with DB2).
Every time when i try to DB2 in Windows command prompt window, I receive this error:
DB21061E Command line environment not initialized.
and per this document using just this step:
2. at the prompt enter these commands:
db2cmd -i -w db2clpsetcp
echo %DB2CLP%
I fix that error, and "db2" command opens Command Line Processor for DB2 Client.
But it lasts only until windows CMD is open. As soon as I close it and reopen, I have to repeat process.
My question (being absolute novice to DB2) is:
How should I make that change permanent and
How this happened at the first place as I installed and setup everything according to the manual (including adding local user to DB2USERS and DB2ADMINS) groups?
When DB2 client is installed, it should have installed a functional window to the command line processor. Check here:
Start / All Programs / IBM DB2 / DB2copy1/ Command Line Processor
Note that DB2copy1 is the default location for the first db2 instance. The name may be different if user select the non-default name.
Shortcut to the CLP can be copied on the desktop.
Regarding the typing "DB2 ..some command..." in windows command prompt which causes described error explanation is as follows:
That's because the normal DOS (or Windows) prompt doesn't
automatically run the setup script that enables the DB2 commands.
When the setup runs, it puts the DB2 items first in the PATH variable.
That could conflict with other tools that also want to be first on the
search list.
If you've got both the DOS (Windows) and DB2 command line prompts on
your desktop, right click them and select Properties. You'll notice
that the system (DOS) prompt runs cmd.exe.
The DB2 prompt runs DB2CMD.exe from the DB2 libraries. The DB2 script
then runs DB2SETCP.BAT and finally DB2.EXE. (All of the DB2
executables should be in C:\Program Files\IBM\SQLLIB\BIN.)
So there are differences in the two prompts. For you purposes, try
running DB2SETCP.BAT from the normal DOS prompt. That may be
sufficient for your needs.
For my purposes I always have the DOS and DB2 prompts on my desktop
and just select the one that I need.

SqlCompare command line remote server

I am trying to use the sqlcompare command line utility to compare a local database and a remote database but I am having difficulty doing this.
I would like to specify a connection string or some way to connect to the remote server (Destination)
Here is the command I have so far:
sqlcompare /Database1:RootDev /Database2:RootProd /scriptFile:"_build\changes.sql" /f
You'll want something along the lines below, using the switches /Server1 and /Server 2 to specify the servers.
sqlcompare /Server1:local\SQL2008 /Database1:RootDev /Server2:remote\SQL2008 /Database2:RootProd /scriptFile:"_build\changes.sql"
Full details on the docs

Using Netsh with PsExec

I'm trying to dump DHCP settings from an older server thats being decommissioned. I ran the command fine while on the actual server but when trying to run it using psexec remotely, it keeps failing. The command is: psexec \\$source netsh dhcp server \\$source dump>$dhcpSettings
$source = the server being decommissioned
$dhcpSettings = the path to save the dumped settings
I've tried all sorts of combinations of encapsulating quotation marks but still nothing. the errors I'm getting is, "The system cannot find the file specified" and "The system cannot find the path specified"
EDIT: So I got rid of the path to save the dumped settings and now it works. But how should I format the command so that it'll save the settings to the remote computer's C:\USER.SET\LOG directory?
One solution might be to bundle the command you want to run and the stdout redirection into a single line cmd file and use PsExec -c or -f to copy and execute that file on the remote system. As an example
Create a line cmd file named DHCPSettings.cmd with the following in it and save it to C:\temp\:
netsh dhcp server \\localhost dump >c:\user.set\log\dhcpsetting.log
Then use
psexec \\$source -c c:\temp\DHCPSettings.cmd
You did not really provide any code to go by and I am not sure I understand the all requirements and constraints you have, so consider this as an idea; not the exact commands you need to run. Hope it helps.

Unable to run PostgreSQL as Windows service

I had this in my Windows services:
C:/Program Files/PostgreSQL/8.4/bin/pg_ctl.exe runservice -N "postgresql-8.4" -D "D:/PostgreSQL/8.4/data" -w
It never finishes executing. But if I did this on the dos shell:
C:/Program Files/PostgreSQL/8.4/bin/pg_ctl.exe start -N "postgresql-8.4" -D "D:/PostgreSQL/8.4/data" -w
Notice that I only changed the "runservice" to "start" and it works just fine.
Any idea?
The command runservice can only be executed by the service manager
in order to fix my localhost windows 7 to start postgres as a service
i used the following command to start the data
pg_ctl -D "C:\Program Files\PostgreSQL\9.1\data" start
Then checked the status for errors
pg_ctl -D "C:\Program Files\PostgreSQL\9.1\data" status
if you get error 1063 , its more than likely permissions, i executed the following command
cacls "C:\Program Files\PostgreSQL\9.1\data" /E /T /C /G postgres:F
then reran the start/status, it showed everything fine, but still service manager would not start the service
So, in Services->postgresql->options->logon i set the log on as the Local system account instead of the postgres user, and voila it worked
this happened to me because i set my data directory to be somewhere the postgres windows user account didn't have access to.
I had this problem in Windows after a system crash. Running the first command showed invalid data in C:\Program Files\PostgreSQL\9.1\data\postmaster.pid. Deleting that file did the trick. Reference.
I faced the same issue after moving manually the database data files (PG_DATA directory) without recreating all the necessary permissions.
Here is how I solved my issue:
1. Check permissions on old PG_DATA directory:
cacls "c:\path\to\old\pgdata\dir"
2. Check permissions on new PG_DATA directory:
cacls "d:\path\to\NEW\pgdata\dir"
3. Compare outputs from 1. and 2.
Find the differences between users and/or permissions then synchronize them.
Nota: I found it easier to use explorer for the synchronization step rather than using cacls directly from the command line.
If you changed pg_hba.conf , maybe you missed somewhere in file. For example there must be CIDR after IP in that file. It must be like 192.168.1.100/32
If you forgot to put 32, then server doesnt restart.
Investigation of startup logs could be a clue. For the case problem is in the pg_hba.conf you could see something like this:
2018-11-13 00:39:34.841 PST [8284] FATAL: could not load pg_hba.conf
2018-11-13 00:39:34.842 PST [8284] LOG: database system is shut down
You need to check your logfiles and the windows eventlog for some hint of what the problem is. If there is nothing at all there, you need to break out something like Process Monitor and get a stacktrace of where it's hung.
I have had this issue in the past, and it was that the installer did not set up the permissions correctly for the user that the service was to run as.
I've also ran into this problem with postgresql throwing and error after trying to initialize the database cluster. After analyzing the log files and running command line scripts for 4 hours I've got the solution to anyone running into this problem for Windows Versions.
This is not a detailed description as to why its happening. I've installed odoo 10, 11, 12 and 13 numerous times on countless client servers and windows systems and this is the first time I've ever ran into this problem. I cant say if its because I have MS VS Enterprise installed and Android Studio on this machine or what. But Below is the easy answer on how to fix it and initialize the cluster and create the database files in the data folder.
Open the data folder for postgresql. - For Odoo installs it will normally be "C:\Program Files (x86)\Odoo 13.0\PostgreSQL" Unless you chose another location when installing.
Remove any or all files from this folder - If not you will get an error when running initdb.exe
Right click the data folder and open up the properties for it. Click on the Security tab and then click the advanced button on the bottom.
You need to change the owner of this folder to openpgsvc. Click Change and type in openpgsvc and click ok. Once done click the check box below saying that you want this change to affect containers with this container as well.
Then on the Permissions tab click the add button on the bottom. You need to add openpgsvc as a user and give this user full rights. Click apply and and ok to close out of all the folder properties.
Now you need to open cmd.exe - Once open we are going to call initdb.exe and pass some values to it as well.
First run chdir and change the working directory to the location of initdb.exe. For me, running odoo 13 on a windows 10 machine the location is this..
"C:\Program Files (x86)\Odoo 13.0\PostgreSQL\bin"
There is one variable that need to be passed as well to make this work here is the list. NEEDS TO BE INCLUDED IN THE CALL TO initdb.exe
Postgres Data Dir: "C:\Program Files (x86)\Odoo 13.0\PostgreSQL\data"
The End Result with the parameter would look like this for my installation:
"C:\Program Files (x86)\Odoo 13.0\PostgreSQL\bin\initdb.exe" -D "C:\Program Files (x86)\Odoo 13.0\PostgreSQL\data"
Hit Enter and let it rip. The output of this command should look like this below.
Cmd.exe running initdb.exe script
Make sure there is no buggy empty file Program at C:\ like C:\Program
In this case, explorer will warn whenever you log on into Windows.
File Name Warning
-----------------
There is a file or folder on your computer called "C:\Program" which
could cause certain applications to not function correctly. Renaming it
to "C:\Program1" would solve this problem. Would you like to rename
it now?
Installing PostgreSQL 10 On Windows 7 (yes the clock is ticking...). I first tried the latest version 11 which completely failed to install... not a good sign for Windows users. Anyway.
Quick answer: Change the account in the Windows Services panel from Network to Local.
Details of my case
During installation I created/selected a data folder in the user profile folder, because obviously the folder suggested by default, within the program folder, wouldn't work, and if it worked it would be a very idea to put data here (I don't know whether it's usual to do that on Unix/Linux, but for Windows it's it's not allowed for a long time).
At the end (when populating the data cluster) I received an error:
Failed to load SQL Modules into database Cluster
but the installation was able to complete. I found two pages about previous error, here and here, but they didn't seem relevant to my case, so I just started pgAdmin and, on the left "browser", saw the server wasn't active.
I tried to start it from here (had to type the main password), but it went inactive immediately again. So I tried to use the Windows services panel to start "postgresql-x64-10", no joy. I copied the command from this panel and pasted it into a Windows console (cmd.exe) where I finally received this
error 1063.
Searching I found this related question, and was convinced the problem was about permissions.
Solution working for my case
In the services panel I changed the account used to start the service from Network Service to Local System as suggested in a comment by #AlexanderRios.
sc create "postgresql-9.2" binPath= "\"C:/Program Files (x86)/PostgreSQL/9.2/bin/pg_ctl.exe\" runservice -N \"postgresql-9.2\" -D \"C:/Program Files (x86)/PostgreSQL/9.2/data\" -w" DisplayName= "postgresql-9.2" start= auto
Try this on CMD run as Administrator
(Add your parameters depend on your version)
Stop all postgres processes
Go to the postgres data folder (C:\Program Files\PostgreSQL\9.6\data)
Delete the postmaster.opts and postmaster.pid files
From the control panel, in administrative
tools and the services console start the postgres service
open pgAdmin III and then in right pane find server then just right click and connect, enter the password. after connected go to the browser and refresh ODOO. Problem solved.
See image to get better understanding