Skip to main content

Posts

Showing posts from 2018

MS SQL Server loop through a list of strings

SQL Server does not have a straight forward way to do a For Loop with a list of string values. The easiest solution I found, can be seen below: DECLARE @ list varchar ( 8000 ) DECLARE @pos INT DECLARE @ len INT DECLARE @ value varchar ( 8000 ) SET @ list = 'A101,A203,B12341,C124,' set @pos = 0 set @ len = 0 WHILE CHARINDEX ( ',' , @ list , @pos+ 1 )> 0 BEGIN set @ len = CHARINDEX ( ',' , @ list , @pos+ 1 ) - @pos set @ value = SUBSTRING (@ list , @pos, @ len ) PRINT @ value -- for debug porpose --DO YOUR MAGIC HERE set @pos = CHARINDEX ( ',' , @ list , @pos+@ len ) + 1 END Please check the original website: https://www.admfactory.com/split-a-string-and-loop-in-sql-server/

Use windows authentication out of the domain

You don't need to have your computer on the domain to use Windows Authentication. Just use the runas command (tested on Windows 10 Home) This is my SQL Server Management Studio shortcut: "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe"  Create a copy of the shortcut and change the target, adding the following to the beginning: %windir%\System32\runas.exe /netonly /user:domain\username  The full target in my shortcut looks like this: %windir%\System32\runas.exe /netonly /user:domain\username "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe" Notice that I also changed the Shortcut Name to Windows Authentication and the icon as well   When I double click the new shortcut, I'm asked for my domain user password And once I'm authenticated, I can open a database using Windows Authentication.

Node.js - Querying from MS SqlServer and loading into DynamoDB

This is a script made with a collation of internet examples. The goal here is to load a DynamoDB table with records from a SQLServer table. For this example I'm using a local installation of DynamoDB. var Connection = require ( ' tedious ' ) . Connection ; var Request = require ( ' tedious ' ) . Request ; var TYPES = require ( ' tedious ' ) . TYPES ; var fs = require ( ' fs ' ) ; var AWS = require ( " aws-sdk " ) ; console . time ( " dbsave " ) ; // SQL Server configuration var config = { userName : ' username ' , password : ' password ' , server : ' serverIP ' , options : { //instanceName: 'MSSQLSERVER', -- didnt have to use this option port : 1433 , database : ' dbname ' } } // DynamoDB configuration AWS . config . update ( { region : " us-west-2 " , en...

NodeJS MSSQL connection error "EINVALIDSTATE"

It took me some time to find the reasons for the connection error below: Requests can only be made in the LoggedIn state, n…", code: "EINVALIDSTATE" I was trying to connect to MS Sql server using Node JS TEDIOUS package. The code from the Microsoft  is very simple and didn't return a more complete error message. This is the original code: ... var connection = new Connection(config);  connection.on( 'connect' , function ( err ) {  // If no error, then good to proceed.  console .log( "Connected" );  executeStatement(); }); ... Checking the internet a bit more, I found a way to get more insight into the error: ... var  connection =  new  Connection(config);  connection.on( 'connect' ,  function ( err )  {  if (err) return console.error(err);   console .log( "Connected" );  executeStatement(); }); ... That raised: ConnectionError {message: "Failed to connect to 10.0.0.100:1433 - c...