How to share an Excel file that has a SQL Query Connection - sql

I am trying to share a file containing a table of information pulled from an external SQL query connection. It works fine for me as I have the connections set up on my PC but when I send the file out, it asks for connection credentials. I could go to each PC and enter the credentials but would prefer the end users to open up the file and use it without having to enter any credentials and would like them to be able to refresh the data as and when needed.
How would I set this up or is it even possible?
Thanks in advance.

Your connection string should be using Windows Authentication, and the local user must be a member of a domain group that has the privileges to run the query on SQL Server.
If you go to Connection Properties, open the connection, and click on Definition, the Integrated Security tag should be set to SSPI.

Related

How can I change the VB.NET application connection string after deployment?

I have written a VB.NET application and created a setup file to install the same on the target machine. An ODBC connection is used to connect to SQL Server instance through a DSN.
My development computer used Integrated Security whereas the target computer uses SQL Authentication which requires me to hard code the credentials in the connection string while building the setup file.
I have previously looked up for solutions, but they require one to define the credentials every time the application is run. I have seen an application that requests the credentials the first time it is run or if the connection is unsuccessful, but unfortunately could not retrieve the source code for the same.
Any guidance on similar lines would be helpful.
Add application settings of string type with user scope for the user name and password, lets say username & userpass. Let the User save these values the first time they run your app. Then just incorporate the My.Settings.username and My.Settings.userpass into your connection string.
To save the settings:
My.Settings.username = txt_user.text
My.Settings.Save()
This way the user can change the username & password if required without you having to update your code.

Connecting to different servers in SQL Server

Scenario- We have more than 100 stores and each store has a server. I've created one application to install each users desktop. Their system needs to be connected with their store server, we have local database in place with the application which has procedures which will be interacting with the server. I can't hard code the server name in each procedures and in the SQL, Using DBLink didn't work.
What is the best way to achieve this?
At login page/form in addition to Username and Password, add Server field.
Your app can list any available sql servers on the network if there is only one then connect to it. If more than one put a dialog up to the users to confirm.
You can use:
sqlcmd -L
That will return any visible sql servers
You have to say some way to the Application installed ,which server to connect to..
there are many approaches...
1.Store connection details in a table from which the application can read to like below
storeid connectionstring
1 somestring
So application at startup event,figure out which connection string to connect to..This approach would not require recompiling app and installing it everytime whenever store or connection string changes
2.In WebConfig,store connection details as key value pair like below..
<add key="storeid1" value="server=localhost;database=myDb;uid=myUser;password=myPass;" />
and then connect based on storeid,but this requires change in config file and app installation ,whenever a connection string or Storeid changes

Unable to connect to Linked Server (Excel file) when using SQL account

The Plan
Have HR personnel dump an Excel file of payroll Job Titles to a network share, add that file as a Linked Server in SSMS, use those titles in my ASP.Net web forms. Using a Linked Server instead of importing data to allow HR to update the Job Titles file at their discretion.
The Problem
I can create the Linked Server and query it without issue, so long as I'm in SSMS with Windows Authentication. But, if I try to access the linked server using a SQL account, I first get the error:
Access to the remote server is denied because no login-mapping exists (Error 7416)
The SQL account being used is the same account my web forms use for everything else. The fact that this SQL account doesn't have file permissions isn't surprising though, so an adjustment to the Linked Server's security should do the trick.
The Problem (part 2)
To reduce the number of variables, I moved the Excel file so it's on the same machine as my SQL Server. I'm logged into the machine and logged into SSMS with my domain admin account.
I access the Linked Server's security tab and, to try and cast the widest net possible, I leave the local login (top part) blank and head straight to "Be made with this security context:" and proceed to provide my domain admin credentials. I hit OK, and I get the following:
Not a valid account name or password (Error 7399)
I know the account name and password are good, so what gives?
Other Things
Folks who've ran into similar things have been instructed to change the logon account being used for the SQL Server service, which I've done using my domain admin account (for troubleshooting, atm). This did not fix the problem.
This is what the Linked Server code looks like, although I created it via the GUI (included for sake of completeness):
EXEC master.dbo.sp_addlinkedserver #server = N'ADP_TITLES', #srvproduct=N'', #provider=N'Microsoft.ACE.OLEDB.12.0', #datasrc=N'C:\JOB_TITLE_EXPORT.xlsx', #provstr=N'Excel 12.0 Xml'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'ADP_TITLES',#useself=N'False',#locallogin=NULL,#rmtuser=N'DOMAIN\username',#rmtpassword='########'
The solution appears to be entering "admin" for the remote login, and leave the password blank.
This only works, however, if the file is stored locally. If it's on the network, I still get a 7399 error, but instead of saying the issue is the account name/password, it now says the issue is unspecified.
I can make my project work with a local file though. Since I'll be moving forward with that, I have no need to solicit additional answers.

Which account is used to authenticate ASP.net to SQL when using a trusted connection?

I'm just in the process of trying to properly configure asp.net 4.5 on our IIS servers.
I have been able to navigate and launch an ASPX page that contains no data conenctions sucessfully so I know that the application pool authentication to the local directories is working as it should.
Now though I have a seperate SQL server that is connected to the domain and have a connection string stored in the code that connects the ASPX page to the server using a trusted connection. When running in visual studio debug mode, the connection works fine - but at that point I assume it is using my login credentials.
My question is, when a user calls the aspx page via the browser when hosted on the new IIS7 server, which account is used to call the SQL server when using a trusted connection? - Is it the end users or is it a local account from the IIS server?
When I call a page with data connections embedded I get the error: Login failed for user ADMIN\PCNAME$ ... which is an indication that this is the account that it is using. However this account doesn't exist on the domain that I'm aware of. - Or does it ?!
Thanks in advance,
It will use the account that ASP.NET is running under, as you've worked out. What you usually should do is create a Domain Account (with the right privileges) and run your ASP.NET AppPool under that account. Then a Trusted Connection will use that account for connecting to the database, and as long as you've given it access (which as a Domain Account you can do) it should all work.
Added:
After some back and forth on comments, lets go back to the start: set the new AppPool to run with the domain users account, and recycle the AppPoolo. What is it that says the password is wrong? If it's IIS trying to start the AppPool, then it is extremeny likely that the Password you gave the AppPool IS wrong, or else that the password is set to change on first logon.
If its not IIS, but opening a Database connection, are you sure that the database allows this Domain Account access to the database and the tables within it it will need? What roles have you assigned to this account? Also, what SQL statement is it trying to execute (if it's got far enough to try and execute a statement at all)?
I suggest you put any response in you original question - comments get to be a drag if there are too many of them.

Sql Server Filestream access denied

I have trouble accessing filestream via SqlFileStream. Sql server and IIS7 are on different servers, remote access to Filestream is enabled. Workgroup for both servers is the same.
I've tried everything, including opening user with identical username/passwords on both servers. Didn't work.
Dim sqlFileStream As New SqlTypes.SqlFileStream(filePath, txContext, IO.FileAccess.Read)
I have both filePath and context.
However, when I open server via explorer logged on locally as Administrator, I also get access denied if I try to acesss this share. Any ideas?
Can permissions for this share be edited at all?
The solution to this problem is to have user with same credentials on both sql server machine and IIS machine. Also, application pool identity must be running with these credentials, and connection string must be set to integrated security.
To edit permissions for this share you edit permissions on this table, as the documentation clearly states (funny how this clearly comes to you only after tenth time reading it):
In SQL Server, FILESTREAM data is secured just like other data is secured: by granting permissions at the table or column levels. If a user has permission to the FILESTREAM column in a table, the user can open the associated files.
"Integrated Security = True;" in connection string