Connect from application to SQL Server (ONLY Theoretical!) - sql-server

I don't know how to connect from a self-written application to a SQL Server. I have added an application role to the SQL Server already. Do I need a SQL Server login or only a database user? I know that after I'm connected I can run the procedure sp_setapprole to access the database as an application. How does this work in theory?

You need a connection string
(instructions on how to connect to the SQL Server: URL,PORT,USERNAME,PASSWORD) and a command to be Executed.
I'm sure there are a lot of instructions online for you, just give it a quick google search:
%Programming_Language & "SQL Connection String"

Related

Single user restrictions even if nobody's connected

When using SQL Server Management Studio I try to query a DB created with "Single user" restrictions.
I log in by using SQL Credentials and "sa" user and by running sp_who2 command I double check nobody is connected to the DB, nevertheless when executing a query on a DB table, the system replies:
Database 'MyDB' is already open and can only have one user at a time.
I'd like to understand why I am experiencing this issue.
Can anybody help on this?
When you set a db in "single user" mode you can only open a single connection to the database (more info here).
So when you open SSMS to navigate through database objects you open the only permitted connection. After this any other operation that requires a new connection to the db will fail, for example creating a new query window to write a query.
From MS Docs:
When you start an instance of SQL Server in single-user mode, SQL Server Management Studio can connect to SQL Server. Object Explorer in Management Studio might fail because it requires more than one connection for some operations. To manage SQL Server in single-user mode, execute Transact-SQL statements by connecting only through the Query Editor in Management Studio, or use the sqlcmd utility.
The same happens on premise if you have the SQL Server agent running.
Another advice from MS Docs (if you are running SQL Server on premise):
Stop the SQL Server Agent service before connecting to an instance of SQL Server in single-user mode; otherwise, the SQL Server Agent service uses the connection, thereby blocking it.

How do I resolve encryption error connecting to SQL Server from Oracle SQL Developer

My objective is to use the migration tool in SQL Developer to migrate 2 SQL Server databases to Oracle. I am attempting to connect to a SQL Server database at a remote location using Oracle SQL Developer 4.0.
I have installed jtds.1.3.0.jar per instructions, and get the SQL Server and Sybase tabs in the connection properties window.
I have entered the user, pw, hostname, port, and database name. When I try to Retrieve Database, or connect, I get the error message:
Status : Failure -Test failed: I/O Error: DB server closed connection.
The SQL Server DBA tells me her error logs contain the following error message:
Encryption is required to connect to this server but the client library does not support encryption; the connection has been closed. Please upgrade your client library. [CLIENT: (my computer's IP address)] Error: 17835, Severity: 20, State: 1.
When I look at SQL Server documentation about this error message, it talks about certificates and SQL Server Connection Manager. Some relevant information to show that I've covered the basics:
Using the same connection parameters, I am able to connect to the SQL Server database using Toad for SQL Server.
Using the same connection parameters, a DBA set up an Oracle Transparent Gateway, and I can connect to the SQL Server database using the gateway and a database link. (As far as I know, neither of these methods required a certificate to connect.)
Both of these use ODBC; SQL Developer uses jdbc with TCP/IP.
The DBA assures me TCP/IP connection is turned on for the SQL Server databases.
I have gone into the XML file where SQL Developer stores the connection string. It has the form jdbc:jtds:sqlserver://sql-xxx-xxx.mw.nos.xxx.com:1433/my_db, which looks correct. I have tweaked it by adding the instance name, but no difference. The database has a default instance name, anyway, so it shouldn't be necessary.
A co-worker has been able to connect to a local SQL Server database on the same machine where SQL Developer was running (both on his laptop).
As a workaround, I am also pursuing the possibility of installing SQL Server on a local workstation, and copying the databases there for processing, but I don't know if I can get approval. If you know another tool for migrating from SQL Server to Oracle, please also let me know.
Thanks in advance.

How to deploy ETL package to a remote SQL Server with SQL authentication?

I'm new to ETL so I have developed a simple ETL package, and now I'm going to deploy it to a remote server.
I connect to server using SQL Server authentication, so I go to solution explorer and open deployment wizard, in there in destination tab entered my server ip and then it shows me a error message saying
Login failed for user 'MYDOMAIN\MYUSERNAME'. (.Net SqlClient Data Provider)
As I said earlier I want to use SQL Server authentication to connect to my server, where can I change this settings in SSIS ?
Take a look at the link below. I think it should solve your problem.
On the Specify Target SQL Server page, specify the instance of SQL Server to install the packages to and select an authentication mode. If you select SQL Server Authentication, you must provide a user name and a password.
https://technet.microsoft.com/en-us/library/ms141693(v=sql.110).aspx

Error while trying to connect to SQL Server - localhost

I have checked the instance name, auto close is set to true, allow remote connections on the server is checked. The server is running when I open the SQL Server configuration manager. I have even rebooted. I have created this db the same way as all others. I use Entity Framework and have checked the names in the web.config and they match. This is the default connection string from the wizard - I use for testing before I deploy. I just can't think of anything else to check to figure out why it won't connect. Working inside SQL Server everything is fine.
Here is the general error.
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: Shared >Memory Provider, error: 40 - Could not open a connection to SQL Server)
Config:
connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQL_1;attachdbfilename="C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.SQL_1\MSSQL\DATA\A_db.mdf";integrated security=True;connect timeout=10;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
Thanks in advance.
Let me preface this answer by saying that proper setup of a SQL instance is not as easy as Microsoft would like you to think with the entity framework. It's a little bit involved and requires that you put your DBA hat on for a little bit.
The error you have indicates that the web instance is attempting to connect to the SQL server using Windows Integrated Security. This will work fine if (a) the windows user that the process is running as (which can be configured in IIS) is authorized to log on to the SQL server and has a valid login in the database and (b) if the SQL server is on the same machine or in the same domain as the IIS server.
In light of this, I recommend using SQL Server authentication. If you need to know how to do this, I recommend searching for "SQL Server Authentication setup" - here is an article that I found which might help you set this up.
http://msdn.microsoft.com/en-us/library/aa337562.aspx
In general, I recommend taking the following actions:
Connect to the sql server using MS SQL Management Studio.
Permanently attach your database, then use the Initial Catalog property on your connection string rather than AttachDbFileName
Then set up your login username and password on the SQL server, and create a login in the database for it.
Make sure your login can only execute the stored procedures you want it to execute. Deny it access to running sql statements.
You will also need to add the username and password to your connection string, and set IntegratedSecurity=false.
Let us know how things go once you get your SQL server set up properly.
This error means that your provider code cannot find the SQL Server. If you have checked the server instance name (it should be <yourLocalServer>\SQL_1), then it could be the attachdbfilename= parameter, as this is a really unreliable way to specify the database to connect to (you should be using the Database Name, not the file name), because there are about a hundred reasons that the file name could change that have nothing to do with your application.

Client side application help requested

I am testing an application. In tableadapter configuration wizard, On server side:
While choosing data source, I chose Microsoft SQL Server Database File.
This gave the connection string as:
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True
Is this correct?
Any way this works in my desired way.
Then in SQL Server Mgmt Express, I attached the database to the instance of my SQL Server Express (to MyhomeServer\SQLExpress"
Now I want to use the same application on Client side (off course databse is stored in Data Directory of my application in Server Side) Now in tableadapter wizard, I choose Microsoft SQL Server Express. Is that correct?
I have done all configurations for remote connection etc. and also done the firewall settings. When I run this test on client side, it returns error:
Cannot open database "Database1.mdf" requested by the login. The login failed. Login failed for user 'MYHOMESERVER\Kh. Furqn'.
Why does it go to Kh. Furqan while I am giving it SQLExpress, where the DB is attached. My server is MyHomeServer\SQLExpress and connection is MyHomeServer\Kh. Furqan (Authentication is Windows Authentication, and no password for it)
Since you chose integrated security the program will try to log onto SQL Server with the current logged on user's credentials - 'MYHOMESERVER\Kh. Furqn'. So the first place I would check is make sure that you can log onto Sql Server Mgmt Studio (SSMS) Express with the windows logon option and logged into the server as Kh. Furqn. Let me know if that works.
Wade

Resources