For each loop in SSIS - Need to understand ServerName and ConnectionString - sql-server

I am trying to use a for loop to connect to different servers and then do some job for each server. In the "expressions" of the connection manager for my loop, i see ServerName and ConnectionString.
I don't know the difference between ServerName and ConnectionString. If I put an ip address inside my servername variable,will i be able to connect to a data base ? If i use connectionstring, will i have to put username and password in that ? How do I know which one to use ?

The server name is just a component of a connection string. A connection string specifies different properties of how you connect to a server. Such as credentials (user name, password, etc). Based on your other question that I'm trying to help you through, you want to set server name.

Think of the server name as the name of the machine. The connection string includes the name of the database and what account you are going to use to connect.
The server name is just one part of the connection string.

Related

SSIS: Configuration of Dynamic Connection String Integrated Security Mode

Setup
In the local environments, we're using SQL Authentication with Username and Password to connect to the databases. I created a Project Connection Manager that has expressions bound to Project Properties, Username and Password being set to sensitive.
On the dev server, when the SSIS run, it needs to use an AD account. I might need to create a Credential/Proxy for the SQL Agent, but for now I'm logged in as the user and I execute the packag through SQL.
Problem
In the SSIS project itself, I'm trying to configure a dynamic connection string to use Integrated Security in one case, and SQL Account in another. I just can't figure out how to do it. Things I tried:
1- Created a boolean "UseIntegratedSecurity" parameter. In the connection string, use that bool to set IntegratedSecurity=SSPI or not with the expression, and also use expressions to set the other attributes of the connection string individually. It didn't work, said the connection string could not be built.
2- Created a boolean "UseIntegratedSecurity" parameter, and write my connection string as something (ugly) like: #[$Project::IntegratedSecurity] ? "Data Source="+#[$Project::SqlServerName]+";Initial Catalog="+#[$Project::SqlServerDatabase]+";Provider=SQLNCLI11.1;Auto Translate=False;Integrated Security=SSPI;" : "Data Source="+#[$Project::SqlServerName]+";Initial Catalog="+#[$Project::SqlServerDatabase]+";Provider=SQLNCLI11.1;Auto Translate=False;User ID="+#[$Project::SqlServerUsername]+";Password=" + #[$Project::SqlServerPassword]
It didn't work because since SqlServerUserName and SqlServerPassword are sensitive, it refuses.
3- Tried having Project Parameters for ConnectionString, Server, Database, User, Password and setting them all. Works locally, but on the server, I get "Invalid Authorization Specifications".
Ideas?
Thanks
You need to handle situation when in one environment you have to use SQL Authentication, and on the other - AD Authentication.
This can be done with help of SSIS Catalog Environment variables. When you create a Project file, Visual Studio automatically creates the following so called project connection parameters for each OLEDB connection manager :
CM.< conn manager name >.ConnectionString
CM.< conn manager name >.InitialCatalog
CM.< conn manager name >.Password Created as sensitive param
CM.< conn manager name >.ServerName
CM.< conn manager name >.UserName
OLEDB is an example, SSIS creates similar parameters for other connection manager types.
Important fact, you do not have to create additional project parameters. The parameters mentioned are created on project being built and are present on all projects.
We create environment variables which specify connection string, DB name (initial catalog), Server Name etc. Good thing - Connection string variable is applied first, and then amended with the other variables.
More details on these parameters is in MS Docs.
In case similar to yours, in Dev environment - using SQL Auth define Conn string for SQL Auth and specify username and password in corresponding variables. In QA env where SSPI is used - the Connection string is reworked for SSPI, UserName and Password environment variables are empty.

How can i find the Hostname of Remote database in Toad

i am trying to connect to the remote database.With given username and password ,i am able to connect in toad.but in the code while handling connection pooling i am getting null connection.so i want to recheck the hostname for this particular DB?how can i check it in Toad?
String url = "jdbc:oracle:thin:#hostname:dbname";
connection = DriverManager.getConnection(url,"username","password");
System.out.println("got the connection"+connection);
i tried connecting using the credentials which i am havving but i getting null connection.i want to recheck the hostname..any idea how can i check the hostname in toad for remote Database?
You may try this:
SELECT host_name FROM v$instance

How to connect to simple database table?

I don't know much about databases - Sorry if the question seems silly.
I have sql server 2012 on my machine and i create simple database table.
I want to connect to this database table thru C# code.
So, I need to know my ConnectionString.
I don't understand the parameters of the ConnectionString.
I try to google it - but still didn't find any good explanation.
Anyone can please explain the connectionString fields ?
How to define the connectionString that i will be able to connect the local database ?
thanks
Your connection string should be as simple as like below
Data Source=.;Initial Catalog=DB_NAME;Integrated Security=True"
Where
Data Source=. means local database
Initial Catalog=DB_NAME means the database it will connect to
Integrated Security=True means it will use windows authentication (no user name and password needed; it will use logged in credential)
Take a look Here
(OR)
Search in Google with key term sqlconncectionstring which will fetch you many help.
EDIT:
You are getting exception cause Initial Catalog=DB_Name\Table_001. It should be Initial Catalog=DB_Name (only database name). Provide the table name in sql query to execute. Check some online tutorial to get more idea on the same.
You use . in data source only when you are connecting to local machine database and to the default SQL Server instance. Else if you are using different server and named SQL Server instance then your connection string should look like
using(SqlConnection sqlConnection = new SqlConnection())
{
sqlConnection.ConnectionString =
#"Data Source=Actual_server_name\actual_sqlserver_instance_name;
Initial Catalog=actual_database_name_Name;
Integrated Security=True;";
sqlConnection.Open();
}
In case you are using local machine but named SQL Server instance then use
Data Source=.\actual_sqlserver_instance_name;
Initial Catalog=Actual_Database_NAME;Integrated Security=True"
using System.Data.SqlClient;
Then create a SqlConnection and specifying the connection string.
SqlConnection myConnection = new SqlConnection("user id=username;" +
"password=password;server=serverurl;" +
"Trusted_Connection=yes;" +
"database=database; " +
"connection timeout=30");
Note: line break in connection string is for formatting purposes only
SqlConnection.ConnectionString
The connection string is simply a compilation of options and values to specify how and what to connect to. Upon investigating the Visual Studio .NET help files I discovered that several fields had multiple names that worked the same, like Password and Pwd work interchangeably.
User ID
The User ID is used when you are using SQL Authentication. In my experience this is ignored when using a Trusted_Connection, or Windows Authentication. If the username is associated with a password Password or Pwd will be used.
"user id=userid;"
Password or Pwd
The password field is to be used with the User ID, it just wouldn't make sense to log in without a username, just a password. Both Password and Pwd are completely interchangeable.
"Password=validpassword;"-or-
"Pwd=validpassword;"
Data Source or Server or Address or Addr or Network Address
Upon looking in the MSDN documentation I found that there are several ways to specify the network address. The documentation mentions no differences between them and they appear to be interchangeable. The address is an valid network address, for brevity I am only using the localhost address in the examples.
"Data Source=localhost;"
-or-
"Server=localhost;"
-or-
"Address=localhost;"-or-"Addr=localhost;"
-or-"Network Address=localhost;"
Integrated Sercurity or Trusted_Connection
Integrated Security and Trusted_Connection are used to specify wheter the connnection is secure, such as Windows Authentication or SSPI. The recognized values are true, false, and sspi. According to the MSDN documentation sspi is equivalent to true. Note: I do not know how SSPI works, or affects the connection.
Connect Timeout or Connection Timeout
These specify the time, in seconds, to wait for the server to respond before generating an error. The default value is 15 (seconds).
"Connect Timeout=10;"-or-
"Connection Timeout=10;"
Initial Catalog or Database
Initial Catalog and Database are simply two ways of selecting the database associated with the connection.
"Inital Catalog=main;"
-or-
"Database=main;"

"Server" vs "Data Source" in connection string

I'm new to SqlServer, right now I have SqlLocalDb installed to work locally. Good, but I can see two connection strings typically and both works:
Data Source=(localdb)\v11.0;Integrated Security=true;
and
Server=(localdb)\v11.0;Integrated Security=true;
What exact difference is there between the two?
For the full list of all of the connection string keywords, including those that are entirely synonymous, please refer to the SqlConnection.ConnectionString documentation:
These are all entirely equivalent:
Data Source
Server
Address
Addr
Network Address
... There is no difference between Server and Data Source as they represent the same thing for SQL Server : the full name of the SQL Server instance with the syntax "MyComputerName\MyShortInstanceName" , potentially including the port used by the SQL Server instance to communicate.
Reference: http://social.msdn.microsoft.com/Forums/en/sqldataaccess/thread/7e3cd9b2-4eed-4103-a07a-5ca2cd33bd21
They are synonymous - you can use either one.
That is - as far as the framework is concerned, they are the same.
My favorite set up is one that doesn't contain any spaces. In the simplest form, one has to provide four values - the URL, the container, the user and the credential.
server
database
user (or uid)
password (or pwd)
So a connection string looks like this.
server=stuffy.databases.net;database=stuffy;user=konrad;password=Abc123(.)(.);

How to connect to other system Database?

Using VB6 and SQL Server 2005
I want to write a sql connection for connecting to other system sql server.
Code
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI; Persist Security Info=False;Initial Catalog=STAR;Data Source=" & SName & ""
In SName - Am giving a Server Name
The Above connection code is working for the same system, Suppose I want to connect to other system database means
For example
I run the program in system A, the Database in system B. How to write a sql connection
Is possible with IP Address like SName = 192.12.12.1/System B
How to Write a connection string.
Need Code Help.
It depends on your network / DNS, you should be able to enter the machine name, you may also need a domain name.
SQL Server also has something called Named Pipes for accessing a SQL instance by it's name - do a google search on that...
Yes, you can use an IP address or a machine name but not both. The exact syntax is
Data Source=192.12.12.1; Initial Catalog=STAR; User Id=abc; Password=def;
In case, you have a trust established between the two servers, then you can replace the User Id and Password part by using Integrated Security=True just like you are doing if the database and program exist on the same machine.
Various types of connection strings are discussed here: http://connectionstrings.com/sql-server-2005

Resources