Database creation

Open
#151 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
docker, powershell, sql
Domain
databases, devops

Research direction

Start with start.ps1 around line 41 and the attach_dbs startup path; inspect how Invoke-Sqlcmd handles the generated attach command. Reproduce the provided Windows container command and determine the expected behavior when the database is absent. Done means the startup behavior is resolved or clearly documented for the reported case.

Written by the indexing model from the issue text.

Description

Hi,

Should the container create the specified database during startup if it does not exist. I'm running this:

docker run --ip 172.16.13.30 --net MyNatNetwork -p 1433:1433 -v C:/temp/:C:/temp/ --env attach_dbs="[{'dbName':'test','dbFiles':['C:\\temp\\test.mdf','C:\\temp\\test_log.ldf']}]" microsoft/mssql-server-2016-express-windows

However this throws the following error:

VERBOSE: Starting SQL Server
VERBOSE: Attaching 1 database(s)
VERBOSE: Invoke-Sqlcmd -Query sp_detach_db test;CREATE DATABASE test ON (FILENAME
 = N'C:\temp\test.mdf'),(FILENAME = N'C:\temp\test_log.ldf') FOR ATTACH ;
-ServerInstance '.\SQLEXPRESS'
Invoke-Sqlcmd : The database 'test' does not exist. Supply a valid database
name. To see available databases, use sys.databases.
Unable to open the physical file "C:\temp\test.mdf". Operating system error 2:
"2(The system cannot find the file specified.)".
CREATE DATABASE failed. Some file names listed could not be created. Check
related errors.
At C:\start.ps1:41 char:3
+         Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerS
   hellSqlExecutionException
    + FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShe
   ll.GetScriptCommand
Dominant language
PowerShell
Stars
11.2k
Forks
9.1k
Avg merge
2d 7h
Merged PRs (30d)
14

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/sql-server-samples

All issues in microsoft/sql-server-samples

Similar issues

More Databases issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.