TFS Build: Can't connect to the Database - sql-server

I'm trying to set up TFS build to deploy to my SQL Server Express instance but MSBuild keeps failing with:
C:\Builds\1\portal\Deploy to Portal_Dev\bin\DB.publish.sql: Unable to connect to master or target server 'Portal_Deploy_Dev'. You must have a user with the same password in master or target server 'Portal_Deploy_Dev'.
This is the publishing file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>Portal_Deploy_Dev</TargetDatabaseName>
<DeployScriptFileName>CCA_DB.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=Machine\SQLEXPRESS;Integrated Security=True;User ID=username;Password=password;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False</TargetConnectionString>
<ProfileVersionNumber>1</ProfileVersionNumber>
</PropertyGroup>
</Project>
Command line parameters used:
/t:Build;Publish
/p:SqlPublishProfilePath=..\DB\Publishing\Portal_Deploy_Dev.publish.xml

First try to build and deploy the project in Visual Studio by right clicking and choosing publish then selecting the profile or use the command line(msbuild) on the build agent.
This will narrow down if the issue is related to TFS definition or not. Check if there are any invalid DNS entry for the database server. Open the firewall on target machine. Also try to update SSDT to the latest version.
More ways for troubleshooting you could take a look at similar error in below questions:
Deploy 72002 - Unable to connect to master or target server
SQL Server DB Deployment : Unable to connect to master or target server

I had the same problem a few weeks ago, in my case in the connection string we weren't having the username and password because we made the connection to the database using windows authentication, I mean when you choose the connection for the publish profile.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseName>MyDatabase</TargetDatabaseName>
<DeployScriptFileName>MyDatabaseChanges.sql</DeployScriptFileName>
<BlockOnPossibleDataLoss>True</BlockOnPossibleDataLoss>
<IgnoreRoleMembership>True</IgnoreRoleMembership>
<IgnorePermissions>True</IgnorePermissions>
<ExcludeServerAuditSpecifications>True</ExcludeServerAuditSpecifications>
<ExcludeServerRoleMembership>True</ExcludeServerRoleMembership>
<ExcludeServerRoles>True</ExcludeServerRoles>
<ExcludeUsers>True</ExcludeUsers>
<ExcludeLogins>True</ExcludeLogins>
<IgnoreUserSettingsObjects>True</IgnoreUserSettingsObjects>
<ProfileVersionNumber>1</ProfileVersionNumber>
<TargetConnectionString>Data Source=MyServer;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True</TargetConnectionString>
</PropertyGroup>
</Project>
Then in the TFS, we use the username and password (as part of the MSBuild arguments),
/p:TargetUserName="$(user)" /p:TargetPassword="$(password)"
we were connecting to the database with that user, now the error was fixed just given it to the TFS TargetUserName the db_owner role and the user was a local user and we changed to network user. I hope that helps you.

Related

Error when running a .net core web app with React.js on IIS 10

I have a web app based on .net core v2.1 with a React.js front-end, which I'm trying to host on IIS 10. The app runs fine via Visual Studio (2017), however when I publish the app and host via IIS, I get the following error:
Error image
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Error Code 0x8007000d
The web.config file was generated during the publish; I have not modified it:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\SkillsMatrix.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: ea8a300c-5bb6-4a29-a8d2-d13dddbbac1d-->
This same error happens if I start a brand new project via VS, do not add any code, and publish it to IIS...
I have tried:
Giving access to the folder/file to the IIS_IUSRS user group
Removing app.UseHttpsRedirection(); in StartUp.cs
Does anyone have any suggestions for how I can clear this error and host my app?
You could try the below steps to resolve the issue:
1)Make sure you download and install the .net core hosting bundle and runtime.
https://dotnet.microsoft.com/download/dotnet-core/3.1
2)Make sure that the Application Pool > Process Model > Identity is set to ApplicationPoolIdentity or your custom identity has the correct permissions to access the application's deployment folder.
3)Set the application pool set the .NET CLR version to No Managed Code:
4)Confirm that you have enabled the proper server role. See IIS Configuration.
you could the below link for more detail:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1

SQL Server using Windows Authentication in Wildfly as service

I'm configuring a datasource to use windows authentication with SQL Server.
I put the DLL sqljdbc_auth.dll in C:\Program Files\XXXX\wildfly-10.1.0.Final\bin
Stating Wildfly using standalone.bat works fine.
But using windows service I got this error:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "Scope_Build36" requested by the login. The login failed. ClientConnectionId:831c2f7f-4352-4467-b54f-a6eb1369d6e9
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:251)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:81)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$1LogonProcessor.complete(SQLServerConnection.java:2825)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:3079)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2360)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:43)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2346)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:6276)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1793)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1404)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1068)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:904)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:451)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1014)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:321)
... 44 more
DataSource configuration:
<datasource jta="true" jndi-name="java:/datasources/PortalScopeWeb_Scope" pool-name="PortalScopeWeb_Scope" enabled="true" use-ccm="true">
<connection-url>jdbc:sqlserver://RI001421D\SQLEXPRESS:1433;databasename=Scope_Build36;integratedSecurity=true</connection-url>
<driver>sqlServer</driver>
<security>
<security-domain>securityDomainPortalScopeWeb_Scope</security-domain>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<validate-on-match>true</validate-on-match>
<background-validation>false</background-validation>
</validation>
</datasource>
Putting DDL in folder C:\Program Files\XXXX\wildfly-10.1.0.Final\bin\service\amd64 don't solved the problem.
you can use a .udl file to test and verify your connection.
In you desktop create a new .txt file, and rename it like "test.udl". Now, open it, and you can configure and test your connection. When you have the connection ready, you can open the .udl file with notepad and copy connection string.
here you have a reference: udl reference
hope this help!

SSDT Unit Test:. An error occurred while SQL Server unit testing settings were being read from the configuration file

I created a database project in Visual Studio 2013 professional. Then added a unit test by right click on one of the stored procedure and select Create Unit Tests. Selected to create a new VB test project. Then right click on the newly created test project and select SQL Server Test Configuration, choose localdb database and configured the project that need to be deployed.
Rebuild the solution, Run All tests (two tests). Tests always fail with this error:
Message: An error occurred while SQL Server unit testing settings were being read from the configuration file. Click the test project, open the SQL Server Test Configuration dialog box from the SQL menu, add the settings to the dialog box, and rebuild the project.
StackTrace:
at Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestService.OpenProcessConfig()
at Microsoft.Data.Tools.Schema.Sql.UnitTesting.SqlDatabaseTestService.DeployDatabaseProject()
at *************.Tests.SqlDatabaseSetup.InitializeAssembly(TestContext ctx) in C:\Projects*********************.Tests\SqlDatabaseSetup.vb:line 15
It seems to be that the app.config that is get generated by VS 2013 is empty. I did some research online and lots of try and error and came with the following app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="system.data.localdb" type="System.Data.LocalDBConfigurationSection,System.Data,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
<section name="SqlUnitTesting_VS2013" type="Microsoft.Data.Tools.Schema.Sql.UnitTesting.Configuration.SqlUnitTestingSection, Microsoft.Data.Tools.Schema.Sql.UnitTesting, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</configSections>
<system.data.localdb>
<localdbinstances>
<add name="(localdb)\ProjectsV12" version="12.0" />
</localdbinstances>
</system.data.localdb>
<SqlUnitTesting_VS2013>
<DatabaseDeployment DatabaseProjectFileName="..\..\..\Database_Project_Name\Database_Project_Name.sqlproj"
Configuration="Debug" />
<DataGeneration ClearDatabase="true" />
<ExecutionContext Provider="System.Data.SqlClient" ConnectionString="Data Source=(localdb)\ProjectsV12;Initial Catalog=Database_Name;Integrated Security=True;Pooling=False;Connect Timeout=30"
CommandTimeout="30" />
<PrivilegedContext Provider="System.Data.SqlClient" ConnectionString="Data Source=(localdb)\ProjectsV12;Initial Catalog=Database_Name;Integrated Security=True;Pooling=False;Connect Timeout=30"
CommandTimeout="30" />
</SqlUnitTesting_VS2013>
</configuration>
Now I get the following error:
Failed to deploy database project C:\Projects\Database_Project_Name\Database_Project_Name\Database_Project_Name.sqlproj. But this seems to be because my database depends on other databases and I need to deploy the other database with my database.

Database connection pointing to wrong database

I have a web project in eclipse using glassfish. I have the following datasource entries in context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/TestDS" type="javax.sql.DataSource"
url="jdbc:oracle:thin:#server:1521:db1"
driverClassName="oracle.jdbc.OracleDriver" username="test" password="test" />
</Context>
When I run my application
DatabaseMetaData dmd = connection.getMetaData();
String name = dmd.getDatabaseProductName();
Database product name is always Apache Derby
What could be the reason for this? I am trying to connect to Oracle Database however connection is made to Apache Derby.
How can I resolve this issue?
Thanks
Update 1
public static DatabaseConnection getInstance(String name)
throws DatabaseException {
DatabaseConnection instance;
DataSource ds;
try {
InitialContext ctx = new InitialContext();
ds = (DataSource) new InitialContext().lookup("java:comp/env/"
+ name);
} catch (NamingException e) {
e.printStackTrace();
throw new DatabaseException("###data source is invalid ###" + e);
}
instance = new MYDataSource(ds);
return instance;
}
seems as if you are mixing some stuff up here. context.xml obviously is a Apache Tomcat configuration file. In GlassFish you need to either use the glassfish-resources.xml or configure your domain directly via either the admin GUI or the domain.xml.
There is a basic example of how to do this with GlassFish 3.1 in the GlassFish docs:
http://docs.oracle.com/cd/E18930_01/html/821-2416/ggndx.html
Have fun!
Markus
I have resolved this issue.
I created a a JDBC Resource under GlassFish and pointed connection to my connection created under Date Source Explorer. It created a sun-resources.xml. I had to manually rename this to glassfish-resource.xml. By default there are no entry for password,so I had to manually add <property name="Passwrod" value="password" />. When I ran my web application I was getting this error
java.sql.SQLException: Error in allocating a connection. Cause: No PasswordCredential found
So to resolve this error I added a property in JDBC Connection Pool in glassfish admin server. Now I could connect to Oracle database.
Not sure why I have to do two steps manually.
Thanks

From Netbeans Dev to Tomcat Production: DB Connection Not Found

I developed a Java web application in Netbeans 6.5 using a MySQL database and Hibernate. Both the development database server and development application server (Tomcat 6) reside on my development machine. Everything works; the application pulls data from the database correctly.
Now, I'm ready to move it to the production server. Again, the DB server and app server are on the same machine. I deploy the WAR file and try to access the application; I can access the static pages but the Servlets that use the database error out with the exception:
org.hibernate.exception.JDBCConnectionException: Cannot open connection
I'm pretty sure the problem relates to Tomcat not knowing about the data source. It seems as if Netbeans handles this for me. I've read that I might need to add a RESOURCE entry so I took some advice from this site which gave me a context.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/EmployeeDirectory">
<Resource
name="jdbc/employeedirectory" auth="Container"
type="javax.sql.DataSource" username="EmployeeDir"
password="EmployeeDirectory" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/EmployeeDirectory?autoReconnect=true"
maxActive="15" maxIdle="7"
validationQuery="Select 1" />
</Context>
a web.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Omit Servlet Info -->
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/employeedirectory</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
and a hibernate.cfg.xml of:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/employeedirectory</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Omit other Mappings -->
<mapping class="EmployeeDirectory.data.PhoneNumber" resource="EmployeeDirectory/data/PhoneNumber.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Now, I get a org.hibernate.HibernateException: Could not find datasource error.
Am I on the right path for moving from development to production? What am I missing?
I think you are on the right track. I would first set up the datasource and verify it out side of hibernate. Here is a good article on that: http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.htm and some examples here: http://www.mbaworld.com/docs/jndi-datasource-examples-howto.html
Then, I would configure hibernate to use the datsource. From looking at your hibernate.cfg.xml file I think you should try changing hibernate.connection.datasource to jdbc/employeedirectory
the jndi datasource should be defined in /tomcat/server.xml see Tomcat JNDI Datasource how-to and not in webapp/context.xml
Tomcat 6 requires that you add the resource tag to the context.xml, not the server.xml. You could in Tomcat 5.x. I have it working fine in a separate install of Tomcat, but I'm still trying to use connection pooling inside NB 6.5.
That same Apache site has a link to the Tomcat 6 version of JNDI and it tells you to add the resource tag to the context.xml.

Resources