Running flyway to migrate db to Azure SQL db: Unable to obtain connection from database - azure-sql-database

I have a flyway script that I run to migrate my db to Azure SQL db. Looks something like this:
flyway.url=jdbc:sqlserver://myazuresqlserver.database.windows.net/myazuresqldatabase;ssl=request;integratedSecurity=false;
flyway.user=myazuresqluser
flyway.password=myazuresqlpassword
...
And when I run it I get the following error:
Unable to obtain connection from database (jdbc:sqlserver://myazuresqlserver.database.windows.net/myazuresqldatabase;ssl=request;integratedSecurity=false;) for user 'myazuresqluser': The TCP/IP connection to the host dbserver-appinfra-test-000.database.windows.net/sqldb-appinfra-smartsuitemainoperational, port 1433 has failed. Error: "myazuresqlserver.database.windows.net/myazuresqldatabase. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
So the thing is I already have one db that I migrated to another Azure SQL db. The script file for that one was almost idetical to the one I am using to migrate this database. I saw posts similar to mine, and, as you can see, I tried adding stuff like "ssl=request" to the connection string, which didn't work, and also setting setting the minimum required TLS version of the azure sql db to the lowest one.
So, because I followed the exact same steps for the other database and it the migration to Azure worked there, I looked closely into the connection strings of my azure databases. Both of the databases are on the same azure SQL server that I created, and both of them are in the same elastic pool that I created.
From my understanding the problem is that, looking at the connection strings, both of the database have this in their connection strings:
myazuresqlserver:1433
Also, important to mention - I did try to connect to this database from Azure Data Studio and SSMS. And it connects just fine
So I think they are both on the same port of the same server, that is the problem.
Could someone let me know how I could change the port of my Azure SQL database to something else in Azure? Or if it is unrelated please let me know what I can do. Help much appreciated!

The problem was in the line flyway.url=jdbc:sqlserver://myazuresqlserver.database.windows.net/myazuresqldatabase
This is what I had in my other flyway migration file (which worked perfectly) so I thought there shouldn't be any problem with this line. But I had to change it to
flyway.url=jdbc:sqlserver://myazuresqlserver.database.windows.net;database=myazuresqldatabase;
Hope this will help someone!

Related

What is the difference between Microsoft SQL Server Connection and Generic DB connection provided in DB connector from Mule 4.3?

In the current project we are already using generic db connection and now we found that there is Sql Serve connection available but we have never used that so want to explore that option.
Is it going to give better performance than generic connection?
One observation from my experience is Generic Connection is working for Windows Authentication where as SqlServer Connection is not working for the same and working for Sql Account.
The Microsoft SQL Server Connection provides some database specific configurations to simplify the configuration of the connection. For example an instance name. With the Generic Connection you can only use generic JDBC configurations. There should not be a difference in performance. Depending on how did you configure Windows Authentication in the generic connection it may or not be possible to replicate it in the Microsoft SQL Server Connection. If you are happy with your current connection configuration there is no need to change it.

Connecting to local server in SQL Server Management Studio

I have tried EVERY suggestion I have found so far in SE and nothing works. Let me explain what is going on.
I am a PHP developer and I am making a transition to ASP. So I am developing a website locally and I need a database going, also locally. But like I said, I can't add the NORTHWND database because I don't have the server up and running. I read through the tutorials and I seen to be missing a piece of every puzzle.
I have SQL Server 2008 running.
These guys Add Database say to attach the database via VS12. I have no such option to "Attach"
These guys here Connect to your server say to connect to the SQL server but I can't connect. When I try, I get an error that says:
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: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
(.Net SqlClient Data Provider)
I also noticed there was a localdb with username LOTUSMS. I don't remember ever making a username for anything here. And I can't remove it or make one up. (Windows Authentication)
And then these guys Turn on your Server Service say the Server must be up and running and to log into the SQL server Configuration Manager and ensure the SQL services are running. Well, they are not. It says "the remote procedure call failed" and there is no other options to restart or edit or anything
So as you can see, I know my problems, but I can't find the solution to them. Anyone? I am not sure as to what logs or extra evidence you may need, so before I go adding unnecessary text and pics here, I'll leave it open and produce the evidence as requested.
Thanks in advance

Microsoft OLE DB Provider for SQL Server error '80004005'

I have migrated a classic ASP site to a new server and am getting the following error, message.
I have tried different connection strings but none of them work.
I am not even sure if the connection string is the problem
The new server is a Windows 2012 Server, SQL Server 2008 R2 Express machine.
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
/scripts/dbcode.asp, line 31
Application("C2M_ConnectionString") = "Provider=SQLNCLI10;Server=(local);Database=mysite_live;Uid=mysitec_Live;Pwd=mypass;"
If it is an Express instance, it is most likely not a default instance, but rather a named instance. So you probably meant:
... "Provider=SQLNCLI10;Server=.\SQLEXPRESS; ...
--- instead of just (local) ---^^^^^^^^^^^^
Otherwise you'll need to show us the server properties in SQL Server Configuration Manager on that machine in order for us to be able to tell you how to correct your connection string.
As Aaron Bertrand mentioned it would be interesting to have a look at your connection properties (In Sql Server configuration check if the following are enabled Name Pipes and TCP/Ip).
Since you're able to connect from SSMS i would ask to check if the Remote connection is allowed on that server Also can you tell is the Sql browser service is running?
here is a link that i keep close to me as a reminder or check list on probable connection issues on SQL Server.
Sql Connection Issues
And lastly can you try as provider "SQLNCLI" instead of "SQLNCLI10"
Step-1: Enabling TCP/IP Protocol
Start >> All Programs >> Microsoft SQL Server >> Configuration Tools >> SQL Server Configuration Manager >> SQL Server Network Configuration >> Protocols for MSSQLSERVER >> right click “TCP/IP” and select “Enable”.
Step-2: change specific machine name in Data Source attributes'value to (local) will resovle the problem ni SQL SERVER 2012.
Try pinging the server in your connection string. The server your application resides on should be able to communicate on the port you specify by credentials. If you are developing locally try specifying "localhost". If the server is clustered or you installed as an instance then you need to specify that instance. Also make sure the server is configured for mixed-mode authentication if using sql credentials.
OR Try
Data Source=localhost;Initial Catalog=DBNAME;Persist Security Info=True;User ID=MyUserName; Password=MyPassword;
It can be a permission issue , Please check is that server is connecting with same configuration detail from SQL management.
other is username / password is wrong.
Here is what I would do:
EDIT: Note that this SO post, a few down, has an interesting method for creating the correct connection string to use.
Open SSMS (Sql Server Management Studio) and copy/paste the
username/password. Don't type them, copy/paste. Verify there isn't
an issue.
Fire up the code (this is next for me b/c this would be the next
easiest thing to do in my case) and step to line 31 to verify that
everything is setup properly. Here is some info on how to do
this. I understand that this may be impossible for you with this
being on production so you might skip this step. If at all possible
though, I'd set this up on my local machine and verify that there is
no issue connecting locally. If I get this error locally, then I
have a better chance at fixing it.
Verify that Provider=SQLNCLI10 is installed on the production
server. I would follow this SO post, probably the answer posted
by gbn.
You have other working websites? Are any of them classic asp? Even
if not, I'd compare the connection string in another site to the one
that you are using here. Make sure there are no obvious differences.
Fire up SQL Server Profiler and start tracing. Connect to the site
and cause the error then go to profiler and see if it gives you an
additional error information.
If all of that fails, I would start going through this.
Sorry I can't just point to something and say, there's the problem!
Good luck!
Have you ever tried SQL Server OLE DB driver connection string:
"Provider=sqloledb;Data Source=(local);Initial Catalog=mysite_live;User Id=mysitec_Live;Password=mypass;"
or ODBC driver:
"Driver={SQL Server};Server=SERVERNAME;Trusted_Connection=no;Database=mysite_live;Uid=mysitec_Live;Pwd=mypass;"
At least this is what I would do if nothing helps. Maybe you will be able to get more useful error information.
Could this be a x86/x64 thing?
The following thread seems to indicate that the (local) alias is a 32-bit alias which fails on 64-bit server:
http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/c701d510-90e5-4dd0-b14f-ca1d694d6615
(note that the error is exacly what you had)
When you were testing the .udl on the server did you test both x86 and x64?
Following the advice from this blogpost (http://blogs.msdn.com/b/farukcelik/archive/2007/12/31/udl-test-on-a-64-bit-machine.aspx) you could test your
local udl :
in 64-bit by just double clicking it (acts the same as running "C:\Program Files\Common Files\System\Ole DB\oledb32.dll",OpenDSLFile C:\\test.udl
in 32-bit by double running C:\Windows\syswow64\rundll32.exe "C:\Program Files (x86)\Common Files\System\Ole DB\oledb32.dll",OpenDSLFile C:\\test.udl
If you can confirm it's a problem with the alias I'd suggest you create a new one by following the guidelines found here:
http://msdn.microsoft.com/en-us/library/ms190445(v=sql.105).aspx
Have you tried to use the server IP address instead of the "(local)"?
Something like "Server=192.168.1.1;" (clearly you need to use the real IP address of your server)
In case you try to use the server IP address, check in the "SQL-Server configurator" that SQL Server is listening on the IP address you use in your connection. (SQL Server Configurator screenshot)
Other useful thing to check / try:
And check also if the DB is in the default SQL Server instance, or if it is in a named instance.
Do you have checked if the firewall have the TCP/IP rule for opening the port of you SQL Server?
Have you tried to connect to SQL Server using other software that use the TCP/IP connection?
The SQL Server Browser service is disabled by default on installation. I'd recommend that you enable and start it. For more information, see this link and the section titled "Using SQL Server Browser" for an explanation of why this might be your problem.
If you don't wish to enable the service, you can enable TCP/IP protocol (it's disabled by default), specify a static port number, and use 127.0.01,<port number> to identify the server.
In line 31:
cmd.ActiveConnection = Application("C2M_ConnectionString")
How are you instantiating cmd?
Rather than the ConnectionString being wrong, maybe cmd is acting differently in the new environment.
Edited to add:
I see that you've gone from IIS 7 to IIS 8. To run Classic ASP sites on IIS 7 required manual changes to server defaults, such as "allow parent paths." Is it possible that some of the needed tweaks didn't get migrated over?
If you're not running with Option Strict On, you should try that - it often reveals the source of subtle problems like this. (Of course, first you'll be forced to declare all your variables, which is very tedious with finished code.)

2-Tier SQL Server database example in VB.net

I'm currently working on a project that requires connection to a SQL Server 2008 database over a LAN network. I intend using one computer as a server where the database will be on, while the others will connect to the server. I've done a thorough search but couldn't find any material on this. All the examples and materials I've seen seem to skip the topic of database connection over a LAN. Does anyone know how I can do this? I would like to see a simple code showing how this is done (in VB.net since that's the language that I'm using).
Connecting to SQL Server over the network is no different to connecting to SQL Server on your local machine. Simply...
Using Conn As New SqlConnection(connstring)
//Do something here
End Using
For information about your connection string have a look at connectionstrings.com
There are a few gotchas though that have more to do with networking and firewalls than any code you will have to write so before you start make sure you can connect to your server with SQL Server Management Studio or similar. Make sure you SQL Server is configured to allow incoming connections.
Depending on the nature of your application and the number of users this may not be the best archictecture. Make sure you are using windows authentication as you really don't want to be storing SQL Connection Strings with username and passwords in config files on the client machines.

Problem connecting to database after a RESTORE. SQL Server 2005 and Classic ASP

I have some Selenium test scripts which I'm using to test a Classic ASP web app, but I'm having problems after restoring the database (SQL Server 2005) with a backup file before every test is run. Immediately after the successful RESTORE (from a Python script running sqlcmd ...) when the ASP tries to connect to the db I get the following error...
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (send()).,,,Microsoft OLE DB Provider for ODBC
This is being generated by ADODB using this connection string...
"DSN=mydbdsn;UID=myuser;PWD=mypass;"
But trying to connect from a C++ ActiveX object via ODBC also fails with the same error.
Restarting IIS gets things back to normal. And SQL Server 2008 exhibits the same issue.
Does anyone have any idea why I can't connect to the database after a RESTORE?
Thanks,
Copying over from serverfault duplicate question:
From the RESTORE specifications:
During an offline restore, if the
specified database is in use, RESTORE
forces the users off after a short
delay.
So make sure you open new connections after the restore. Existing connections from the connection pool are all busted by RESTORE, as clearly documented. Clear your connection pool before each test.
I would guess that this is something to do with connection pooling and your connection being killed when the database is put into single user mode for the restore.
Is there any text in the error message other than what is in your question?
Sounds like the connection to the server is being cached somewhere. Either connection pooling is established or your code is leaking connections somewhere... which is likely with classic asp.
Sounds like you might just want to make an IISRESET call part of your data restore plan.