Sep 9 2023

MSSQL restore all databases from folder with .bak files

Powershell

Install-Module dbatools
Import-Module dbatools
Set-DbatoolsInsecureConnection -SessionOnly
Restore-DbaDatabase -SqlInstance SERVER-NAME\INSTANCE-NAME -Path 'C:\PATH-TO-BACKUPS'
Sep 2 2023

MSSQL: User, group, or role ‘platnik’ already exists in the current database.

lists logins and incorrect SIDs
USE <platnik_db>
GO
EXEC sp_change_users_login 'Report'
GO

Then start SQL
USE <platnik_db>
GO
EXEC sp_change_users_login 'Auto_Fix','<user_name>',NULL, '<password>'
GO

Sep 2 2023

Delete multiple databases in MSSQL

drop databases query

USE master;
Go
SELECT 'DROP DATABASE ['+ name + ']'
FROM sys.databases WHERE name like 'PREFIX%';
GO
Aug 27 2023

snapshots of UEFI libvirt-based (KVM) virtual machines

Shut down VM and then

Listing
qemu-img snapshot -l <file>.qcow2
Create
qemu-img snapshot -c <snap-name> <file>.qcow2
Revert to 
qemu-img snapshot -a <snap-name> <file>.qcow2

Delete
qemu-img snapshot -d <snap-name> <file>.qcow2

 

Aug 18 2023

USB NIC reset

lsusb 
Bus 002 Device 002: ID 8087:8000 Intel Corp. Integrated Rate Matching Hub 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
Bus 001 Device 002: ID 8087:8008 Intel Corp. Integrated Rate Matching Hub 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 
Bus 004 Device 003: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter 
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub 
Bus 003 Device 003: ID 04f2:b477 Chicony Electronics Co., Ltd HP HD Webcam 
Bus 003 Device 002: ID 0424:2514 Microchip Technology, Inc. (formerly SMSC) USB 2.0 Hub 
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

then
usbreset 0bda:8153

Aug 13 2023

Windows recovery

bootrec /scanos

bootrec /fixmbr

bootrec /fixboot

bootrec /rebuildbcd

Aug 9 2023

Deletes files older than 30 days

forfiles /p "C:\sql.arch" /s /m *.* /D -30 /C "cmd /c del /Q /S @path"

Jul 15 2023

openvpn renew server cert

Stop openvpn server

List issued certs in
ls -alh /etc/openvpn/easy-rsa/pki/issued
cd /etc/openvpn/easy-rsa
./easy-rsa renew <cert-name>

copy new cert file from /etc/openvpn/easy-rsa/pki/issued
and
new key file from /etc/openvpn/easy-rsa/pki/private
to folder /etc/openvpn

create /etc/openvpn/auth.txt with key’s password
chmod 600 /etc/openvpn/auth.txt

add line to /etc/openvpn/server.conf
askpass /etc/openvpn/auth.txt

start openvpn server

Jun 24 2023

Migracja bazy danych Płatnik z Access 32 bit na MS SQL Server

Instalujemy po kolei

Microsoft Visual C++ Redistributable

Microsoft OLE DB Driver 19 for SQL Server (x64)

Microsoft Access 2016 Runtime

Microsoft SQL Server Migration Assistant (SSMA) for Access

SQL Server Management Studio (SSMS)

Uruchamiamy Migration Assistant (SSMA) for Access

Pomijamy Kreatora

Tools -> Default Project Settings

Zmieniamy “Add timestamp column” na Never

Tools -> Project Settings -> Type Mapping

zmieniamy

date na datetimetext[*..*]
text[*..*] na varchar[*]
memo na varchar[max]

Odpalamy kreatora, wybieramy bazę źródłową <nazwa>.mdb bazę docelową na serwerze MSSQL i wykonujemy konwersję.

 

Uruchom SQL Server Management Studio (SSMS) i usuń ograniczenia dotyczące zerowej długości wszystkich pól

polecenie poniżej wyświetli kwerendę która to zrobi

SELECT
ctu.TABLE_CATALOG
,ctu.TABLE_SCHEMA
,ctu.TABLE_NAME
,ctu.CONSTRAINT_CATALOG
,ctu.CONSTRAINT_SCHEMA
,ctu.CONSTRAINT_NAME
,cc.CHECK_CLAUSE
,[drop_statement]= 'ALTER TABLE [' + ctu.TABLE_CATALOG + '].['+ ctu.TABLE_SCHEMA+ '].[' + ctu.TABLE_NAME + '] DROP CONSTRAINT [' + ctu.CONSTRAINT_NAME +'];'
FROM [platnik].[INFORMATION_SCHEMA].[CONSTRAINT_TABLE_USAGE] ctu
join [platnik].[INFORMATION_SCHEMA].[CHECK_CONSTRAINTS] cc on ctu.CONSTRAINT_NAME=cc.CONSTRAINT_NAME


 

Tworzenie konta dla Płatnika

Uruchom SQL Server Management Studio (SSMS)

Utwórz konto dla bazy docelowej

Security -> Logins

Przejdź do User Mapping i ustaw usera jako właściciela bazy

 


Podłączanie Płatnika

Podłączamy się pod serwer MSSQL używając MSSQL Server Authentication, podając usera i hasło

Jeśli dostaniemy błąd

to zmieniamy sterownik połączenia z MSOLEDBSQL na SQLOLEDB (w moim przypadku musiałem tak zrobić pomimo migracji na MSSQL 2014 Standard)

 

Program accesspassview do odzyskiwania hasła do pliku mdb

Jun 24 2023

SQL Server Configuration Manager

Version Path
SQL Server 2022 C:\Windows\SysWOW64\SQLServerManager16.msc
SQL Server 2019 C:\Windows\SysWOW64\SQLServerManager15.msc
SQL Server 2017 C:\Windows\SysWOW64\SQLServerManager14.msc
SQL Server 2016 C:\Windows\SysWOW64\SQLServerManager13.msc
SQL Server 2014 (12.x) C:\Windows\SysWOW64\SQLServerManager12.msc
SQL Server 2012 (11.x) C:\Windows\SysWOW64\SQLServerManager11.msc