I am writing a C# application to be deployed on another machine. The deploy machine is a clean Windows 7 install.
On my development machine (A Windows 7 32 bit Virtual Machine) I have installed SQL Server 2008 R2 and Visual Studio Express 2010. I would like to create a new database and have it require authentication from an application to connect. All the tutorials that I find mention breeze over the connection string part, I cannot find this explained anywhere. In fact, I cannot even figure out how to add a new user and password to SQL Server in SQL Server Management Studio.
How do I add a new user and password to SQL Management Studio 2008 R2 such that I can easily install another SQL Server instance on another machine and move the database to it?
Thanks.
first check the authentication mode of your DB:
connect to your DB on SSMS, right click it, go to "properties" and then "security". Make sure that "SQL Server and windows authentication mode" is selected. That will allow you to create logins.
Then create your login:
connect to your DB on SSMS, expand your database then go to "security" and right click on logins and then click "new login"
then create your user:
go to the security folder inside your DB, right click users and "new user". Inform the user name and the login name you previous created.
Dont forget to add the necessary permissions
About connection strings, this is a very good website as already pointed:
http://www.connectionstrings.com/
To create a SQL Server Login:
http://msdn.microsoft.com/en-us/library/aa337562.aspx
For Connection strings:
http://www.connectionstrings.com/
Related
I've been trying to connect my Visual basic to SQL because this is what we are taught off but when I execute it, it shows this. How do I fix this?
This Windows user needs to be granted access to SQL Server and that specific database. It is usually configured during installation process of SQL Server. You can still do it by opening SSMS and adding this user under Security -> Logins node from Object Explorer panel.
Of course, to be able to do above, you need to connect to your SQL Server Express first. You may need to use another Windows user or a SQL Server user. The latter would be possible only if SQL Server Authentication has been enabled during installation process by choosing Mixed Mode for authentication (Windows + SQL Server).
You need to get full permission in SQL Server.
Open SSMS there is a Security folder then => Logins.
In Logins you will find your PC's username which is connected to Sql service
Right-click on your username => Properties
Check Windows Authentication Mode
I have developed a C# Winforms app with Visual Studio 2015 which uses a SQL Server 2014 local database.
I used ado.net to connect to database there is the connection string I used:
Data source=reza\mssqlserver2014;inital catalog=storesystem;integated security=true
And it works great on my pc.
What do I need and what should I do to set it up in another computer?
Note that I login to my SQL Server 2014 with Windows authentication mode.
I have tried backing up and restoring the .mdf file to target computer. But it didn't work.
Your app is using Windows Authentication to connect to SQL Server and I suspect your development machine's SQL instance already has been setup to recognise your account.
On the target machine, add the currently logged-in Windows user as a legitimate user for the database in question under Logons.
Though you could arguably move to SQL Server Authentication, a better security model is when the application does not use a password in the first place.
I create application using C# windows forms which uses local SQL Server database server to store / read data using this connection string:
SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=mydb;Integrated Security=True");
After that I created a setup file (exe) then I installed the setup file in same PC and the application works well and can read data from the SQL Server database.
Now the problem came when I went to another PC I installed SQL Server and I manually attached the same database (mydb) and installed my application and it did not work. The error is shown in the screenshot:
I have different SQL Server name in the other PC but I specified in the connection string that the SQL Server is Localhost so I don't know why it didn't work. Please help me how to fix this error. Thank you
Make sure Sql Server is set to allow Tcp/Ip connections and that it's set to allow integrated security logins. Then, make sure the user on that machine is granted the correct access to the database. You may have better luck using Sql authentication over Windows Authentication here, if you want to be able to distribute this application and have it "just work".
Finally, if Sql Server here is meant to be a simple datastore for a typical local desktop application, it's probably overkill. Full Sql Server (including Express Edition) is a server engine. It works best when it's the only thing running on the machine and can use up all of the resources on the machine in order to cache data and handle requests from many remote machines. If you just want a local data store for a typical desktop application, an in-process engine like Sql Server LocalDb, Sql Server Compact Edition, Sqlite, or even MS Access would be a much more appropriate choice.
You need to set up Windows authentication for the user that's logged in on the other computer. Because you are using Integrated Security, it will attempt to connect to SQL Server using the windows login of the current user. This will be a different login on different computers, so the SQL Server on the other computer needs to have that user added.
You need to start SQL Server Browser Service. It lets your app connects to SQL Server:
SQL Server Browser listens for incoming requests for Microsoft SQL
Server resources and provides information about SQL Server instances
installed on the computer.
To enable it:
In SQL Server Configuration Manager, go to Properties => Service tab => Start Mode = Automatic.
Or
This computer => Manage => Services and Applications => Services => SQL Server Broswer
Note: You need a sql specific user for connect to it, you can not go with Integrated Security for every machine.
Create a Sql Server user and allow it to access the Database:
--//Creates the login AbolrousHazem with password '340$Uuxwp7Mcxo7Khy'.
CREATE LOGIN AbolrousHazem
WITH PASSWORD = '340$Uuxwp7Mcxo7Khy';
GO
--//Creates a database user for the login created above.
CREATE USER AbolrousHazem FOR LOGIN AbolrousHazem;
GO
Reference
I have two PC (both have Win7). On PC "A" I have installed Microsoft SQL Server 2008 and developed a Windows application. On PC "A" my application is running well and there is no connectivity issue.
But when I run this application on PC "B" (connected with PC "B" through LAN and able to share any file) it shows error message login failed for user'....'.
I have already make some possible solution but can't solve it.. Need help
My connection string is:
Data Source=WIN7-PC\PRABHAT;Initial Catalog=plproject;User ID= win7-PC\Prabhat;MultipleActiveResultsets=true
Is there any problem?
The SQL Server error log contains addtional information about failed logins. Look there and find the code that maps to the table listed here: https://support.microsoft.com/en-us/kb/555332
One possible issue is that you are running as a machine account that doesn't exist on machine B. You need the Windows identity to flow from one machine to another and this is typically accomplished with a domain service account. If you want it to work from machine B, you need to access it with an account machine B is aware of. Supplying the User ID is typically for SQL Server authentication, not Windows authentication. You could try adding the password and see if that works.
Here is a breakdown of SQL Connection String syntax: https://www.connectionstrings.com/sql-server/
You need to enable TCP/IP for cross machine SQL SERVER access. Just follow below mentioned steps to ensure whether it is enable or disabled.
Click on window start menu.
Navigate to Microsoft SQL SERVER => Configuration Tool => SQL
Server 2008 Configuration Manager.
In Opened window Navigate to SQL SERVER Network Configuration =>
Protocols for <MSSQLSERVER> (Protocols for your SQL server
instance name)
Check Whether TCP/IP is enabled or not.
I have a console app that needs to connect to a remote sql server 2008 instance....
this particular line throws an error even though i have access to that database...
connection.open() is the line that is throwing the error...
Make sure that Sql server 2008 instance available at your system where you are running your application.
Atleast client version of Sql server 2008 should be installed on development machine.
Check connection string and server system also allow network connection.
Make sure the connection string in you console app uses the same credentials and settings that you use to successfully connect in management studio.
Are you using Windows authentication in one place and a SQL login in another?
Have you been able to connect to this remote server before? If you have been able to connect previously, but cannot do so now, that may be an indication that a backup copy of the database, from another server, has been restored to that server.
When you write that you "have access" to that database, how do you connect? Close your copy of SQL Server Management Studio and re-open it; when you get the Connect dialog, be sure to enter the user credentials that your console app uses to connect. Do you see your database? Are you able to execute stored procedures, run SELECT statements, or otherwise do what you would expect?
If you do not see the database--or if you cannot do the activities you expect, you have probably restored a database from another server. This is very common--a database developer is working on the next revision of the database on his development machine; when it comes time to deploy he backs up the database, copies it to the server, and restores the database. Now he can't connect--and can't understand why.
The reason is that the Login and User are presented in the SSMS UI as strings--but in fact they are integer IDs. You will have to do a bit of scripting to delete the invalid User record from the database in order to assign it to the new server's Login.
If this sounds like your problem, respond--I'll check back in a bit, and follow up with more help.
JM