Posts

Showing posts with the label DB

Automating DB Backup under SQL Server Express (Without SQL Agent)

SQL Server Express does not include SQL Server Agent. That means: No Jobs engine No Maintenance Plans (Management → Maintenance Plans does not exist) The same applies to many shared SQL Server environments. If you need automated backups, you must implement your own scheduling solution. The Solution Create a batch file and schedule it using Windows Task Scheduler . The script: Accepts database name as parameter Accepts backup folder as parameter Generates timestamped filename Executes BACKUP DATABASE via sqlcmd Batch File Script @echo off set databaseName=%1 echo %databaseName% set backupFolder=%2 echo %backupFolder% for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%...

TRIM Unwanted Characters from String in SQL (Quick Tip)

Small thing. Useful thing. I didn’t know that TRIM in SQL can remove specific characters — not only spaces. Example TRIM ( '.,! ' FROM '# test .' ) What It Does This removes any of the following characters from both sides of the string: Dot . Comma , Exclamation mark ! Space The result: '# test' Why It’s Useful Cleaning imported data Sanitizing user input Preparing text before comparison Normalizing values for indexing Short. Simple. Powerful.

MongoDB Atlas Cloud Cluster Test – Connecting to .NET Successfully

Today I performed an initial test of MongoDB Atlas , the managed MongoDB Cloud Cluster that can run on different cloud providers. The full setup — from cluster creation to a working connection — took roughly one hour. For a managed distributed database platform, that timing is impressive. Environment Setup The goal was simple: Create a MongoDB Atlas cluster Configure network access Create a database user Connect from a .NET application The cluster provisioning itself was straightforward. The UI is clear, and the workflow is linear: project → cluster → security → connection. Connecting MongoDB Atlas to a .NET Application I successfully connected the cluster to a .NET application using the official MongoDB driver. This was particularly satisfying because about half a year ago, in a previous company, we failed to make it work. At the time, the issue seemed complex. Now I know the root cause. It was only an incorrect connection string. No networking issue. No fir...

SQLite to MS SQL – Import Script Using Linked Server

This post continues the previous article about connecting SQLite to SQL Server using an ODBC driver and a Linked Server. The script below retrieves table metadata from the SQLite linked server into a table variable and prepares a cursor over the table names. This can be used as a base for further automation or dynamic import logic. Retrieve Table Metadata declare @temp table ( col1 varchar(255), col2 varchar(255), [name] varchar(255), [type] varchar(255), col3 varchar(255) ) insert @temp exec sp_tables_ex 'Your_LinkedServer_Name' select * from @temp Create a Cursor Over Table Names DECLARE lstTables CURSOR FOR select [name] from @temp Important Notes The Linked Server must already be configured using the MSDASQL provider. The ODBC DSN must be created as a System DSN , not a User DSN. Make sure the DSN name matches the one used when creating the Linked Server. Do not use spaces in the DSN name to avoid query issues in SQL Server. Summ...

How to Import SQLite Database into MS SQL Server Using ODBC (Step-by-Step Guide)

Image
This guide explains how to connect a SQLite database file to Microsoft SQL Server using an ODBC driver and Linked Server configuration. The same ODBC DSN can also be used to open the database in MS Access. Overview The core requirement is creating a System DSN using a SQLite ODBC driver. Once configured, SQL Server can access the SQLite file through a Linked Server. Step 1 — Install SQLite ODBC Driver Download and install the appropriate version (match SQL Server bitness): http://www.ch-werner.de/sqliteodbc/ Step 2 — Create a System DSN Open ODBC Data Source Administrator: 64-bit: C:\Windows\System32\odbcad32.exe 32-bit: C:\Windows\SysWOW64\odbcad32.exe Create a System DSN and select “SQLite3 ODBC Driver”. Important: Do NOT use spaces in the DSN name. SQL queries against Linked Servers may fail if spaces are used. Step 3 — Create a Linked Server in SQL Server Run the following in SQL Server Management Studio: EXEC sp_addlinkedserver @server = 'SQ...