Connecting to LocalDB from Visual Studio Online Build Server - tfs

I have a library project that has a local MDF file (LocalDB) and uses the following connectionstring:
Data Source=(LocalDb)\v11.0;Initial Catalog=MyDB;Integrated Security=True
The code needs to access the DB in compilation time (F# Type Provider). It works fine locally but it fails when it is compiled on the Visual Studio Online Build Server (TFS) with the following error:
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=26085; handshake=248;
I checked and it looks like LocalDB is installed on the build servers: http://listofsoftwareontfshostedbuildserver.azurewebsites.net/
Any ideas? Do I need special permissions to access LocalDB?
Thanks!

I had a similar problem and I solved it by initializing LocalDb in a post-build event. You might need to put it in a pre-build event if your build itself is accessing the database.
I wanted to have a dynamic LocalDb database created every build in order to access it from my unit test suite. I decided to use the RimDev.AutomationSql package to allow my unit tests to programmatically create the LocalDb instance rather than checking in a .mdf file. (See http://www.nuget.org/packages/RimDev.Automation.Sql/)
According to the RimDev.Automation.Sql github readme, https://github.com/ritterim/automation-sql, even though LocalDb is installed, it may not be initialized.
You may have LocalDB installed, but never initialized the instance on
your machine. Run this command via command prompt.
LocalDB SQL Express 2014
"C:\Program Files\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe"
create "v12.0" 12.0 -s
LocalDB SQL Express 2012
"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SqlLocalDB.exe"
create "v11.0" 11.0 -s

Related

SQL Connection string issue when deploying ASP.NET Core MVC to Azure App Service (Linux)

I have created a simple ASP.NET Core MVC application using EF Core and SQL Server. On the Windows development machine it is using localdb. I am trying to deploy to Azure App Service (Linux). I have created an Azure SQL database. Deploying from Visual Studio 2019, I have set the database as a dependency. In the publish profile settings I have selected the Azure SQL connection string for the database context I am using. I have also checked the EF Migrations and on deployment the script successfully created the tables for the application. I can connect to Azure SQL and see the tables. However when I run the deployed application and try a database operation I get: PlatformNotSupportedException: LocalDB is not supported on this platform
I can see from the docs various ways to set the connection string but I would like to know what the publish wizard in Visual Studio 2019 is trying to do and why it is not working? I'm also unclear where the password is stored. In the publish profile the password seems to be in the connection string as plain text, not good. I'd like to know how to get this right for production.
Update I have fixed this for the moment by following the steps in the Linux tutorial, using the Azure CLI and running the following command:
az webapp config connection-string set --resource-group [myResourceGroup] --name [app name] --settings MyDbConnection='[connection-string]' --connection-string-type SQLServer
I am not sure of the security of this approach and plan to investigate further.
The publish wizard simply handles the database creation/migration for you, it doesn't modify your project, as that's 1) not its purpose and 2) it can't make the configuration decision for you (i.e. use appsettings, environment variables, etc.)
You need to provide the connection string in production via configuration, just as in development. Since you're deploying to an Azure App Service, the most logical place for that would be to the App Settings in the Azure. These will be loaded in via environment variables. Simply specify the same key you're using in development and specify the production database target there.

Visual Studio 2017 Web App with SQL Authentication Error 52

I am trying to publish a VS2017 web app to a godaddy domain with authentication on a remote SQL server. The app works fine when run from the Visual Studio environment. I can log in, register, etc and see the data on my SQL Server. When deployed I get ::
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
Fixed - I discovered that the web.config file on the domain server did not get updated with the proper connection string.

TFS Installation error at Configure section of Application Tier Only Wizard

When doing Application Tier only installation on TFS, I received the following error at the Configure section of the Application Tier Only Wizard.
TF255356: The following error occurred when configuring the Team Foundation databases: TF246083: The configuration of Team Foundation Server is not valid. You must remap the databases in order to fix the configuration. The following error was received from the server: TF400673: Unable to find any compatible SQL Analysis Services database within the specified instance.
'2' hosts have been given updated connection strings.
.. For more information, see the configuration log.
How do I resolve this error?
Image Link for Application Tier Only Wizard
This problem usually occurs when Move or Clone Team Foundation Server from one hardware to another.
Based on the error message, seems you have not restored the TFS_Analysis database or somthing wrong with the restored TFS_Analysis database.
So, you can try to restore the TFS_Analysis database, then check it again. If the issue still exists there, then you can refer to below thread and following the steps to fix that:
TFS Configuration
Cloning Your TFS Server Part 02 – Prepare Restored Databases
UPDATE:
You have to restore the TFS_Analysis database first, you can not configure the AT without the DB. Alternatively you can do a complete new installation and create a new TFS deployment. See Install TFS on a single server for details.

0x80004005 Access is Denied on new install of TFS2018 Express. Can't execute roslyn\csc.exe

I've installed TFS2018 Express. It appears to have completely installed.
When I attempt to access its website component, I get the Win32 0x80004005 Access is Denied error. The stack trace references a csc.exe program in a roslyn sub-sub directory. The failing command mentions a file in another directory.
I've seen other threads that say not to run TFS in 32-bit mode. The installer didn't ask me and I don't know how to tell it to act in 64-bit mode.
Other threads say I need to add read and execute permissions to the directory. Which directory/directories? I've added it to the whole website directory and its children plus the referenced file directory.
It seems pretty darn silly for the product to install itself with inadequate permissions and not tell us which permissions are needed.
The error message tells me what command was failing.
[Win32Exception (0x80004005): Access is denied]
[ExternalException (0x80004005): Cannot execute a program. The command being executed was:
"d:\Program Files\Microsoft Team Foundation Server 2018\Application Tier\Web Services\bin\roslyn\csc.exe" /shared /keepalive:"10" /noconfig /fullpaths #"C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\tfs\af7cc5\244hjudj.cmdline"
Just for testing, after fighting it for some time, I gave full control over the roslyn directory and to the TFS (and child) directories to domain users where the cmdline file was mentioned. No change in the error message.
I put the above command into the command line and ran it. I get this error message:
error CS2011: Error opening response file 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\tfs\af7cc5\244hjudj.cmdline'
warning CS2008: No source files specified
error CS1562: Outputs without source must have the /out option specified.
Any ideas?
See https://developercommunity.visualstudio.com/content/problem/165639/0x80004005-access-is-denied-on-new-install-of-tfs2.html# for an answer that worked for me.
Key elements are that the program was installed via the iso installer and it apparently caused the website to run in 32bit mode, when 64bit mode is needed.
This caused the website to recompile to 64bit mode:
Files under C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary
ASP.NET Files are created by ASP.NET compiler. It is very strange that
error message mentions
C:\Windows\Microsoft.NET\Framework\v4.0.30319 instead of
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
since TFS must be running in 64-bit Application Pool. Could you make
sure that "Microsoft Team Foundation Server Application Pool" and
"Microsoft Team Foundation Server Message Queue Application Pool"
application pools are configured to run in 64 bit processes?
To do this you can do the following:
1) Open IIS Manager (inetmgr.exe)
2) Select Application Pools page
3) Select "Microsoft Team Foundation Server Application Pool" click on
"Advanced Settings..." link on the right pane.
4) Make sure that Enable 32-bit Applications is set to False.
5) Repeat steps 3 and 4 for the "Microsoft Team Foundation Server
Message Queue Application Pool"
Once you verified that application pools are configured to run in 64
bit processes, open Sites page in the IIS manager and find out ID of
the Team Foundation Server site (second column). Usually it is 1 or 2.
After that, execute the following from the elevated command prompt:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe
-errorstack -m /LM/W3SVC/1/root/tfs
Replace bold 1 with ID of your Team Foundation Server site.
Does it report any errors?
In my case, the 32bit settings on the application pools were correct, and the aspnet_compiler.exe command caused the website to switch to 64bit mode. After that, all was well.

Using a LocalDb MDF file on Azure

I am developing an ASP.NET MVC website, which I want to host on Azure Websites. While in development, I have been using an MDF file in my App_Data directory with a connection string looking like this:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MyApp;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MyApp.mdf;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
To try it out on Azure, I was hoping I could leave this connection string as is, and simply FTP my MyApp.mdf into the App_Data folder on Azure, since it is all set up with the example data I want to use. However, when I tried to access my site, I ran into the following error:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 52 - Unable to locate a LocalDB
installation. Verify that SQL Server Express is properly installed and
that the LocalDB feature is enabled.)
My question is, is there a way I can run my Azure website connecting to an MDF file in my App_Data folder, or am I forced to use an Azure SQL database?
You can't use an .mdf file in App_Data, but you aren't forced to SQL Azure -- you can use SQL Server Compact. Deployment from LocalDB to Compact is easy if you are using Code First Migrations; otherwise you will have to migrate to SQL Server Compact before you deploy. If you decide to go with Compact you'll have to make sure the database engine gets deployed, and you can find instructions for that in this tutorial:
http://www.asp.net/mvc/tutorials/deployment/deployment-to-a-hosting-provider/deployment-to-a-hosting-provider-deploying-sql-server-compact-databases-2-of-12
You'll have to use SQL Azure to use the Websites/Cloud Service features.
If you haven't already you'll probably want to have a look at web.config transformations with web deploy to ease the publishing experience.
http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
http://www.hanselman.com/blog/TinyHappyFeatures3PublishingImprovementsChainedConfigTransformsAndDeployingASPNETAppsFromTheCommandLine.aspx
You can import your data into the SQL Azure DB via the management tools or if you're using SQL Server 2012 you can import/export data via the portal.

Resources