How to import dataset from SQL Server via VPN connection - sql-server

I need to import dataset from a remote SQL Server using a VPN connection. I would like to know how to proceed. I have no experience in servers.
I am using a shiny app to read and process csv files. Now I am getting a bit more ambitious and I would like to upload directly my data from a remote SQL server. I communicate to this server via a VPN connection.

When you have access to the database via SSMS, You can import file.
you choose the database that you want to import file into.
right click the database and find "Import Data" option under
tasks.
You will be able to choose file type that you are
trying to import. For the Txt, and csv file, please use Flat File
Source as Data Source.

Related

Connect to linked server (Oracle) in SQL Server using Instant Client

I need to connect to a remote database (Oracle) using a MS SQL Server (2019) linked server. What I did so far:
Installed Oracle Instant Client x64 and the ODBC drivers on the machine where the SQL server is running
Created a symlink to the central TNSNAMES.ORA (on a file share in the network) inside the Oracle Instant client folder.
Set the necessary environment variables
Created an ODBC connection to the database on the Oracle server on this machine
Restarted MS SQL Server
Created a linked server (Microsoft OLEDB Provider for ODBC Drivers) in the SQL instance
When connecting to the SQL Server using sqlcmd on this machine (I did not install SSMS there), I can query the linked database using OPENQUERY(). I can also read the file TNSNAMES.ORA using this command (note, the given file is the symlink, but it displays the contents of the linked file, as it should):
SELECT * FROM OPENROWSET(BULK 'C:\InstantClientx64\tnsnames.ora', SINGLE_CLOB) TNSNames
So far, everything is fine.
Now, when I connect to the SQL Server from my workstation using SSMS, i get the following error when trying to read TNSNAMES.ORA using the command above:
Cannot bulk load because the file "C:\InstantClientx64\tnsnames.ora" could not be opened. Operating system error code 5(Access is denied.).
I created a file test.txt in the instant client folder containing something like "Am I allowed to read this?" - and I was, no problems.
I started procmon on the server to find out what happens. When using the above command on the SQL server, I get a REPARSE (because it's a link!), and then SUCCESS, the file is displayed in the sqlcmd console.
When using this command in SSMS (on my local workstation), first appears the REPARSE (OK), then ACCESS DENIED.
In both cases it is the same user account which is displayed as "Impersonating" in the procmon's details. There is definitely no problem with a firewall, and the read permissions on the tnsnames.ora file on the network share are granted for Everyone. I am also able to create an ODBC item on the local workstation, and can connect and query the database from here.
I have done this in the past I don't know how often, and never had problems. What am I missing?
Why are you trying to read the tnsnames.ora file via SQL? The Oracle libraries will (should) internally open it and use it when your app connects to the DB.
The default location for network config files is shown in the Instant Client installation doc. In your case it will be C:\InstantClientx64\network\admin. Unless you have set the TNS_ADMIN variable, then start by creating this subdirectory and putting tnsnames.ora in it.
(A future version of Instant Client on Windows will create the network\admin subdirectory automatically, similar to the way it is created with the Linux Instant Client packages).

Unable to run sql file in SSMS with 2 Database Engine connections(1 is a Server connection and the other is a local database engine)

I have set up 2 separate Database Engine connections in SSMS 2017. One connection is to the company server databases and the other is for my local database instance. Now, when I open SQL files with code referring to the Server Instance (#1), it fails to run because it doesn't recognize the tables or the attributes. I have to right click on the Server Name in the Object Explorer and open A New Query page, copy the code from the SQL file and paste it onto the new Query page and then run it.
How do I get the SQL file to run by opening it and clicking on Execute?
If you are trying to reach a different database instance from your local hosted instance, you will need to create a linked server.
Once you have that in place you can mix the database connections from a single sql file by using 4 part naming conventions [Server].[Database].[Schema].[Table].

Writing a connection string

I am willing to write a connection string to allow one computer connect to another computer's sql server located in the same work group.
Anyway, searching the Internet only confused me and led me to fail tries.
So, if I am willing to connect to an sql express server to a database called "Analyze", what should my connection string look like?
Create a new text file with the extension UDL in a folder.
Right click on the file and click open with "OLE DB Core Services"
Filll in the appropriate entries and save.
Open the file in notepad - voila, your connection string is in there.
Good luck.
There is a post on MSDN explaining how to connect to SQL Server express over a network.
The main points are; you need to configure SQL Server to listen for requests. This can be done using the SQL Browser. You also need to ensure the firewall will allow requests through.

How can I set up a remote connection to a SQL Server 2012 database in the Cloud?

I have connection strings that look like this after I added a few line feeds so it's easy to read:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=xxx.database.windows.net;
Initial Catalog=database2;
Persist Security Info=True;
User ID=xxx;
Password=yyy"
providerName="System.Data.SqlClient"/>
I have two tables one in a local database and one in database2. The tables are in the dbo schema.
If the table in the remote and local databases are both called USERDATA then how can I move data
from my local to remote database. I assume I need to make a remote connection but is that possible
if the database is store in the cloud like this? If possible can someone tell me how I can set up
this remote connection? I have SQL Server Management Studio so I can open a SQL Query window. I am just not sure how to specify the remote connection and if that is the best way to do it.
You can use like this:
INSERT INTO [database2].[dbo].[USERDATA]
SELECT tn.ID, tn.NAME
FROM [database].[dbo].[USERDATA] as tn
or you can use SSDT (Sql Server Data Tools) to migrate your schema and data to Sql Database on Azure.
There are multiple ways of handling this. Two simple ones of the top of my head are:
1) If you just need to transfer data for ONE table your best bet is to use a program called 'bcp' that comes with your SQL Server tools.
bcp allows you to export or import data (using in or out parameters) to a file and very quickly. You can simply use the bcp tool, export a table into a flat file, copy it over to the SQL Server in the cloud (using remote deskop or sharing the file in Azure storage or any other web-based storage) and then import the table again.
2) Alternatively, if you have access to SQL server in the cloud from your premise machine (ie: the firewall is open) and you're to run SSIS, you can connect both of the SQL servers within your SSIS package and transfer the data via SSIS

Deploying SSIS Package and retaining a connection password

I have an SSIS package that queries a view for some records then sends off an email using Database mail. I want to deploy the package to the SQL Server that these views exist in and then schedule us using SQL Server Agent but i've run into a number of issues.
The main problem is that within the job there is a connection manager that has stored credentials for a SQL Server account that has access to the views and email profile. I've set the package to EncryptSensitiveWithPassword instead of User Key but i can't seem to find any way to actually pass that password the the SQL Server Agent when the job is run. So when it executes it fails since it can't connect.
A bunch of websites say to use the config file, but when I go that route it breaks the job entirely complaining that the OLEDB connection can't be established. In that scenario I can't even run the job on my machine locally.
A few other sites recommended copying the package to the local ssis package store on the machine, but I only have access to the machine through SQL Server Tools, I can't remote in or install anything on the file system so I have to install through the manifest file using the SSIS deployment process.
I've read something about storing settings in another DB table, but that again presents issues with permissions on the server.
Finally I tried passing /password or /decrypt in the job scheduler, but when i click ok it scheduler removes that parameter.
This is an internal server and security isnt really a big concern, Any idea how i can pass the decryption password in plaintext or just tell SSIS to not bother securing sensitive data?
The trick is:
When saving the package in SQL Server Business Intelligence Studio, ensure the Package Properties > ProtectionLevel is set to EncryptSensitiveWithUserKey.
When you import the SSIS package into the SQL Server (from SQL Mgmt Studio > object explorer > [server] Integration Services > Stored Packages > MSDB > right-click > Import Package > set Package location to File System, Select the file in Package path, and select the option "Rely on server storage and roles for access control". I would guess when importing the .dtsx file you have to be logged in as the same user that saved the .dtsx file.
This means that the password is saved with the package and therefore can be used when anyone executes the package. If it's something you don't want anyone to execute you then lock down security appropriately.
Alternatively you could change the Connection so it uses Integrated Security (windows authentication instead of a sql login) and change the Job so it executes the package as a user that has access to the database & view that's queried by the package. This is the preferred option from the view that you don't need passwords anywhere and instead manage it via user identity and permissions.
It sounds like when you're using the config file that you're not setting up the config file correctly.
What is the exact error that you're receiving when running it locally? I can try to recreate the issue.
do you have the package set up in bids to store the passwords, and then save the package to ssis and tell it to encrypt the passwords? if you're not saving them locally, it could be that you've lost your passwords and then pushed the package without them.

Resources