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.
Related
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
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.
This code was used once to get the Current user's windows logon name.
The application was published on a webserver and this code worked to get the end user's Windows Logon Name, so how could this happen when this code is actually running in the code behind on the server itself?
Dim CurrentUser As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString
Please explain to me if you can.
IIS has a mode called Windows Authentication which (usually when combined with Internet Explorer) will authenticate the user with the server automatically and enable this functionality.
For this to work you usually have to disable anonymous access.
I have an issue with logging a Support user into an Application that has a SQL Server backend.
When configuring the application itself, the SQL set-up asked me to assign whether the Security to access the Application would be Windows Authentication or SQL: server Authentication, I chose Windows Authentication, and as I was using a login called
'LabUser1' I have been able to login to the application fine.
However, when I logon to the server using a different windows login, this time 'Support', SQL keeps giving me the error:
Error accessing the database DSN
Now I know the reason is because the install of SQL happened using the 'Labuser1' profile, but how can I create a script that will allow me to add the 'Support' user to the 'Allowed Logins' so that I can logon to the app server and at least open the Application? (I have seperate logins for when I see the applicatiojn login window, so please don't confuse the matter by thinking it is a simple case of creating a login for Support....I am talking about logging into the server)
The current batch file I am trying to run is:
sqlcmd -S localhost\OCDBB01 -i createSupportlogin.sql
Then I run this batch file after having created the following SQL script:
CREATE LOGIN OCDMW1\Support FROM WINDOWS
GO
Your description of the situation is a bit confusing to me however it appears that the "SQL setup" that is part of the application configuration created a ODBC DSN that uses the credentials of person logging into the machine as the login for SQL Server.
Simply creating a new (correct) login to the SQL instance may not resolve this issue since that does nothing to modify the DSN. If you are tied to using Window Authentication for SQL access it might be necessary to create multiple DSNs for the application to use and find a way to have the correct DSN associated to the right login for the application to use.
I have create a windows service which access SQL db. The connection string is grabbed from the app.config file .
The Following is the format of the connection string
connectionString="Integrated Security=SSPI;Persist Security Info=False;server=xxxxx\SQLEXPRESS;database=Sample;uid=sa;password=xxxxx;Trusted_Connection=False"
The Windows Installer Account Type is LocalSystem.
This service is running of some system successfully, but on some system's its showing login failure for 'SA'.
Please suggest a solution.
It's quite straightforward: login failure for 'SA' refers to the fact that the login sa exists, but the password is not. Particularly, sa is a system default login that always exists, but you have probably set the password differently on different servers.
Another thing to check is whether or not there are multiple instances on the machine. It could be \SQLExpress on one, but the default instance on another that you are meant to connect to.