Run sqlserver to restore database on docker (bitbucket) - sql-server

I want to mount an sql server on Bitbucket so I can download a db (bak file), restore it an upload it later on a main scheme on my server. I've tried:
Mount an SQLServer image, but didnt recognize the path to the downloaded file (problems with mssql tools)
Mount an SQLtool image, but didnt recognize the path too
Python 3.8 image and install sql server and sql tool, but systemctl wasnt found
How can I do this?

Related

How to setup Debezium for Kafka running in Docker for MSSQL Server

I am new to Debezium, Kafka, and Docker. I have successfully installed Docker and it is running on my locahost.
I am attempting to go through the Debezium tutorial at: https://github.com/debezium/debezium-examples/blob/master/tutorial/README.md#debezium-tutorial
I went to the section for SQL Server: and the first step says to # Start the topology as defined in https://debezium.io/docs/tutorial/. I successfully ran through that tutorial. But, it is for MySQL and not MSSQL Server. Anyways, I went back to the ../debezium-tutorial and the first line tells me to run:
export DEBEZIUM_VERSION=1.1
docker-compose -f docker-compose-sqlserver.yaml up
The tutorial does not discuss how to create the docker-compose-sqlserver.yaml. I checked Debezium's github site for this file and it is not there. Am I supposed to create this file manually or am I missing something in the steps?
In order to get Debezium to work, am I supposed to create and run a SQL Server instance in Docker, or can I use the instance that is running on my localhost?
The Docker Compose is included in the tutorials repository.
git clone https://github.com/debezium/debezium-examples.git
cd debezium-examples/tutorial
export DEBEZIUM_VERSION=1.1
docker-compose -f docker-compose-sqlserver.yaml up

Powershell sql server module 2017 manual install

Just installed sql server 2017 RTM. After that I installed SSMS version 17. Funny enough this won't install the powershell module but you have to install it from PowerShell Gallery. Now my servers of course (being an enterprise environment) have no direct connection to the internet and not even the management computers in that domain have. From the Powershell Gallery website I was not able to manually install the powershell module. Question is do anybody here managed to have latest sql server powershell module installed for sql server 2017?
I'm not in an environment to test this but one method would be to install the module on a computer/server that does have access to the internet, download and install it there, locate the module, and then copy it to the other server and import it. So, something like:
On the other computer (with internet access):
Install-Module -Name SqlServer
(Get-Module -ListAvailable SqlServer).Path
Go to the path and copy the file(s) to the same location on the other server. Then, on the other server, and run:
Import-Module -Name SqlServer
This assumes that both hosts are running the same version of Powershell; or at least compatible ones.

How to import a shape file into SQL Server?

In the past I have used shape2sql to import shape files into SQL Server.
I tried that route again on a newer Windows 10 box, and nothing seems to happen when trying to use that application.
Any suggestions for either getting shape2sql to work, or alternative ways to upload shape files into SQL Server?
So, it turns out that ogr2ogr has the ability to import directly into a SQL Server database now. I created a temporary database and did the following:
Install ogr2ogr via the GDAL core MSI installer from http://www.gisinternals.com/release.php
Open a command line to the installed path
Run the following:
ogr2ogr -overwrite -f MSSQLSpatial -lco “GEOM_TYPE=geography” -a_srs
"EPSG:4326"
"MSSQL:server=.;database=temp_import;trusted_connection=yes" "[path to
shape file]"
I've managed to import successfully on remote server. Here goes procedure
Install QGIS Desktop 3.10.5..or whatever version is actual.
How to find out what goes to parameter -a_srs, in my casa that is : -a_srs "EPSG:3765":
Open QGIS Desktop 3.10.5, open new project and drag-drop your shape file to Layers left sidebar. Right click on that layer and go to Properties. There you will be able to read your -a_srs information.
Run command in CMD:
C:\Program Files\QGIS 3.10\bin>ogr2ogr -progress -f "MSSQLSpatial" "MSSQL:server=xxx.xxx.xxx.xxx,yyyy;database=yourDB;UID=yourUse;PWD=yourPassword" "C:\Users\Username\Desktop\ShapeFiles\Name_of_shape_file.shp" -a_srs "EPSG:3765" -lco PRECISION=NO
Where xxx.xxx.xxx.xxx - IP address of your server
yyyy - port number of your server if you are running SQL Server on different port than standard (I think you can omit that in case you are)
Output:
0...10...20...30...40...50...Warning 1: Ring Self-intersection at or near point 664451.64629999956 5053409.8562000087
60...70...80...90...100 - done.

Deploy the database to Docker Container microsoft/mssql-server-linux

I have a database running on SQL Server (13.01) on Windows. I like to deploy it to the Docker Container on Linux using SSDT.
I can perfectly connect to the server running on Docker and create/drop database manually and play with the data.
The problem is I can not publish it. I'm executing following script on Powershell
PS: SqlPackage.exe /Action:Publish /SourceFile:"d.dacpac" /TargetConnectionString:"server=containeraddress;database=thedatabase;user id=sa;password=thepassword;
and getting the following error.
Unable to connect to master or target server 'the database'. You must have a user with the same password in master or target server 'the database'. (Microsoft.Data.Tools.Schema.Sql)
I have the same user and same password on target and source servers.
Is there anybody has the same problem and know how to solve it?
I'll post this here as most of the answers refer to having an existing compiled dacpac file, which may not always be possible. I haven't seen similar ideas posted elsewhere to the solution I'm suggesting here.
Given your usage of docker and if you wish to compile your visual studio project inside the container, given certain combinations of the container base OS and image may not be possible to create a dacpac file with msbuild.
You can work around restoring the database using a series of unix based commands, taking note that the visual studio database project is usually just a series of SQL files, below I show an example of this, where I concat the SQL files into a single file and call sqlcmd to run the script;
FROM mcr.microsoft.com/mssql/server
WORKDIR /init
ENV ACCEPT_EULA=Y
ENV MSSQL_SA_PASSWORD=MyPassword
EXPOSE 1433:1433
RUN apt-get update && apt-get install dos2unix
COPY /solution_folder/database/Tables/*.sql /init/
WORKDIR /database
RUN echo "CREATE DATABASE [database_name];\nGO\nUSE [database_name];\n” >> /database/create.sql
RUN for f in /init/*.sql; do dos2unix $f; cat $f >> /database/create.sql; echo "\nGO\n" >> /database/create.sql; done
RUN ( /opt/mssql/bin/sqlservr --accept-eula & ) | grep -q "Service Broker manager has started" && /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ‘MyPassword’ -i /database/create.sql && pkill sqlservr
The reason for "dos2unix" is that the SQL files created within visual studio have unique hidden cr/lf (and other characters) which the linux version of sqlcmd won't interpret successfully and will cause errors (which is kind of bizarre and this is exactly the kind of thing you'd want a cross platform database to be able to cope with)
Also, within the final run command you have to start-up the sql server service temporarily otherwise you'll also get errors; it's a little bit of work-around, and a bit fiddly and I'm not sure entirely that the microsoft sql server linux container is well designed enough for the simple task of restoring a database like this, the nuances are the differences between building and running a container and needing some sort of happy middle ground of both concepts for it to work.
Given here isn't a complete solution to restore, it only deals with Tables from the project file, although it should be trivial to expand to scalar functions and stored procedures.
Which version of SqlPackage.exe are you using? Only the most recent release candidate versions of SqlPackage.exe support SQL Server vNext CTP. The SqlPackage release candidate can be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=54273

Connect to database in App_Data folder

Is it possible to connect to a database in the App_Data project folder using the command line? I'm trying to test some SQL statements outside of the VS environment.
I tried using the below, but that didn't seem to work:
sqlcmd -S .\Sqlexpress -d [location of mdf]
Not sure about the app_data folder, but if you have the db files running off of a sql install, you can use sqlcmd command line which is installed with the sql client tools or the sql feature pack (sql native client).

Resources