Explanation on creating a connection string for a SQL Server - sql-server

I'm working on connecting my SQL database to Shiprush that has SQL integration. I've went through all of the steps and read through the information on creating a SQL string, but mine didn't work.
At first I tried a SQL string like this
Provide=SQLOLEDB; Server=Localhost; Database=DBNAME; User Id=ID; Password=psw;
However I realized that it wasn't local. So, I tried to use my IP address and port number like this but it also failed.
Provide=SQLOLEDB; Data Source=myIPv4:1433; Initial Catalog=DBNAME; User Id=ID; Password=psw;
The database is listening on port 1433. I have to use the provider SQLOLEDB. Shiprush says when I try to access the database:
The connection string property has not been initialized
How can I get the connection string working?

Related

SQL server connection happening on different port without specifying port in connection string

There is a SQL Server instance on server which is listening on different port 1550 other than 1433. When I am trying to connect it from other server without specifying the port number in connection string the connection is working fine. I want to understand how is that happening? Is it something to do with SQL browser service? This setup was done by someone else which I am not aware of.
Also I have checked the firewall, there is no port forwarding in place. Can anyone explain how that is happening?
Since it was the case of server migration, The database was migrated to new server and password hash were not synced properly. One of our DBA had ran the query to auto_fix it but that query didn't work. Later on when he updated the password hash again everything started working.

Sql Server Connection String Changes When Local and Remote

Hopefully this will be an easy one.
I have several projects that use a Sql Server 2012 instance on one of our cloud servers. When I am developing on that server my connection string must be .\SERVER_NAME but when I am connecting to it remotely the connection string must be IP_ADDRESS, PORT_NUMBER. I sometimes forget to change the connection string from local to remote when I push to the production environment.
Is there a way to make both the local and remote connection string the same? Also is there a way to avoid having the port number in the remote address?
Any help would be much appreciated.
As for the port, the default SQL SERVER port is 1433, if that is the port you are sending then it isn't necessary. As for having one connectionstring or not changing the name you could do a couple of things I guess...
Here are some options:
Add a post deployment task where the correctly configured .config file is copied to the target.
Code machine specific connections, so both conn strings would be in the web/app .config and based on the runtime machine dictates what conn string you use.
Add an entry in your host file for the server, on dev it points to DEV Server while on the other sever it points to the other.
Not sure why you must use an IP address and not a name, you must not have any DNS?

SQL Server Connection issues

I have 2 SQL Server instances installed on my Windows 7 :
First one : SQLEXPRESS - no specific database
The other one : MSSQLSERVER (classical) - several development databases...
Let's say my computer's name is SERVERNAME
Using connection string SERVERNAME\SQLEXPRESS is ok.
Using connection string . is ok and connects to MSSQLSERVER instance
Using connection string SERVERNAME does not work
Using connection string SERVERNAME\ does work (note the backslash).
Thus, until yesterday the SERVERNAME connection was working fine.
And everybody's telling me that the SERVERNAME\ connection is a abnormal one.
I've tried to connect with Windows authentication and SQL Server authentication, and cannot connect through SERVERNAME as my server name.
What should I do to recover previous functionality ?
Thanks in advance.
Regards.
You should always use SERVER_NAME\INSTANCE_NAME. In you above described scenario when you use . which means localhost it connect you the the sql server default instance name. but is it really safe to let sql server decide which instance to connect to? obviously not.
Let your connection string decide which server and what instance to connect to by using full path i.e ServerName\InstanceName. and do not worry much about other issue. as they say Keep it simple :)

DBVisualizer/SQL Explorer will not connect to the right DB instance

I am trying to connect to a SQL Server instance in DBVisualizer on ubuntu and for some reason unknown to me it incessantly connects to the wrong instance. The target is a Windows Server that is running multiple instances of SQL Server on it. I am trying to connect to it using the following string:
jdbc:sqlserver://srv\sql2:1433;DatabaseName=CloudServices
However quite amusingly, it continuously connects to srv\sql1 even though my connection string points to sql2 and not sql1. I can connect to the right db instance (sql2) using SSMS on Windows perfectly fine.
I am having the same issue when I try to connect to this DB using SQL Explorer in Eclipse
Am I missing something here?
Not sure if you still need the answer for this but try using this connection string in DBvisulizer.
jdbc:sqlserver://srv\sql2:1433;Instance=INSERTYOURINSTANCEHERE;DatabaseName=CloudServices
Port 1433 is the static port of the default instance. Try connecting to the redirector on port 1434 and specifying the instance name property in your connection string.

JDBC connect string for SQL Server cluster

I need to setup a JDBC connection string to SQL Server.
This question is similar to the the C# ADO.Net connection question. This one is specific to JDBC connection strings.
The usual format for the JDBC string is "jdbc:sqlserver://{host}:{port}".
Now, for a SQL server cluster I have a cluster name vvv\iii ({virtual server}{instance name}).
There's no problem setting up an ODBC connection through the "New Data Source to SQL Server" wizard when using the vvv\iii string as the server name. However it seems the JDBC connection string requires a specific host and port.
Is there a way to make a JDBC connect string to a SQL Server cluster?
it turns out that you can use the "instanceName" property within the JDBC string, as documented on the Microsoft Technet page in section "Named and Multiple SQL Server Instances". What worked in my case was the following string for virtual server vvv and database instance name iii:
"jdbc:sqlserver://vvv;instanceName=iii"
When using a SQL Server named instance in a cluster or stand alone environment each SQL Server instance is dynamically assigned a port number on startup. The SQL Server Browser server handles requests to each instance because each server restart could change the port number used by each instance. The first instance to start on a server reboot gets assigned 1433 but there is no guarantee if you have 2 instances that one of them will always get 1433. There are several veriables that affect the startup and recovery time it takes for an instance to start. This can change each time.
That being sad... when connecting to a named instance the jdbc connection string should look like this:
jdbc:sqlserver://server_name/db_name;instance=instance_name
rather than this
jdbc:sqlserver://server_name:1433/db_name;instance=instance_name
note that the default database "/db_name" is optional. If exclued the connection will use the default database assigned to the SQL Server login.
The cluster resource has a host name and a listening port. Use jdbc:sqlserver://{virtualserver}:1433 (or the appropriate listening port if not listening on the default one).
I'd comment Mark Stewart's remark, but the reputation is lacking. My source doesn't mention /db_name and I can't get it to work either. Maybe another case of confused instance names?
Make sure you leave the port definition off as the cluster determine this for you.
So my datasource definition looks like:
jdbc:sqlserver://sqlcluster_hostname\instancename;DATABASENAME=databasename;sendStringParametersAsUnicode=false;SelectMethod=direct
I ran into this issue while trying to setup a Railo datasource to connect to MSSQL cluster.
Slightly off topic ... The standard Railo datasource MSSQL driver option sets the port to "-1" if you leave the port field empty however if you set it to "0" then it removes the port definition altogether and then everything works. But the best way is to choose 'Other - JDBC Driver' to define the JDBC connection string in full as above.

Resources