Showing posts with label sql server. Show all posts
Showing posts with label sql server. Show all posts

Thursday, August 23, 2012

SQL Server Database Project - Warning is shown as Error

While trying to build a database project, I was getting an error:
Error:  SQL01945: Warning! The maximum key length is 900 bytes. The index 'xxx' has maximum length of 1024 bytes. For some combination of large values, the insert/update operation will fail.

Although this was a warning, the project was failing to build and it was shown as a error.

The fix was to edit the project file in xml and set TreatTSqlWarningsAsErrors to False

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <OutputPath>.\sql\debug\</OutputPath>
    <BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
    <TargetDatabase>xxx</TargetDatabase>
    <TreatTSqlWarningsAsErrors>False</TreatTSqlWarningsAsErrors>
    <SuppressTSqlWarnings />
    <NoWarn>
    </NoWarn>
  </PropertyGroup>

SSDT Conversion - SQL72027: File master.dacpac does not exist.

I was converting a database project to SSDT by following the steps at http://msdn.microsoft.com/en-us/library/hh272689(v=vs.103).aspx

The conversion was successful but when I tried to build the sqlproj, it gave the following error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets(494,5): Error:  SQL72027: File "<project directory>\master.dacpac" does not exist.

To fix this error master.dacpac needs to be copied in the project directory.
If the Target Plaform is "SQL Azure", it can be copied from
"D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\SQLDB\Extensions\SqlServer\Azure\SQLSchemas"

Otherwise based on the platform, copy from the corresponding directory from
"D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\SQLDB\Extensions\SqlServer"

Monday, August 20, 2012

SqlPackage.exe - Automating SSDT Deployment

To know about SQL Server Data Tools (SSDT), take a look at http://msdn.microsoft.com/en-us/library/hh272686(v=vs.103).aspx

Below are the steps for automating the SSDT deployment:
  • Create a Folder on the deployment machine. We can call it C:\SSDT
  • Make sure the files from the following folders on the development machine are copied in SSDT folder on the deployment machine:
    • C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin
    • C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SqlServer.TransactSql.ScriptDom\v4.0_11.0.0.0__89845dcd8080cc91
  • Copy the files from the Build Output of the SSDT Project in a Folder on the deployment machine. We can call it C:\Build
  • Make sure that you have the connection string of the Target Database where you want to depoy. We can call it connStr
  • Now you can publish or generate the scripts for the database deployment (Steps are same for Full or Incremental Deployment)
    • To Publish, run the command: C:\SSDT\SqlPackage.exe /Action:Publish /SourceFile:"C:\Build\MyDatabase.dacpac" /TargetConnectionString:"connStr"
    • To Generate Scripts, run the command: C:\SSDT\SqlPackage.exe /Action:Script /SourceFile:"C:\Build\MyDatabase.dacpac" /TargetConnectionString:"connStr" /OutPutPath:"C:\Build\MyDatabase.sql"
This is great feature for SQL Azure databases since incremental updates can be applied very easily without making the sql scripts SQL Azure compatible.

Thursday, June 16, 2011

How to Kill open connections to a Database

I came across a scenario when I wanted to restore a Database. However I was getting an error saying the databse is already in use. I needed to find who was connected to the databse and kill that connection.
So I first ran the command exec sp_who
This gave me the spid of the connection.
Then I ran the commad kill _spid to kill this connection.