I wrote simple sql script that creates my database:
create database [MaterialStream];
exec sp_addlogin N'MaterialStreamLogin', N'123', N'MaterialStream'
exec sp_adduser N'MaterialStreamLogin', N'MaterialStreamUser', N'db_owner'
And then couldn't connect to my database from ADO.NET. How can I set up credentials for my user?
Have you tried logging on as that user using Management Studio? It's possible it's defaulted to requesting a password change on first login or similar.
Related
My boss said
"To do so, SCRIPT the real database using SQL Manager / Tasks
RUN that script locally in a Query Window on your own machine to create a local copy of the database.
Note: Your new database will have all Tables and Procedures but will have NO data in it. You will need to add your own "dummy data" to make things work for you as you test.
Create a second connection string in your web.config that connects to your local database
use that connection string for your development work
However i don't actually understand how to do that.
Follow these steps:
1. Connect to your remote server from SQL Server Management Studio.
2. In object explorer, right click on your database and select Tasks>Generate Scripts.
3. Click on Next and then again click on Next.
4. Select the file system path where you want to save the database script for the database and click on Next
5. Click on Next. A .sql file will generated.
6. Connect to your local server from SQL Server Management Studio.
7. Open the newly created database script in SQL Server Management Studio and execute it. A copy of your database on remote server will
be created on your local server.
Additionally to the answer above, change the connection string in your web.config by changing the name of the data source to your Server Name (the name you use to get into SQL Server) and change the initial catalog to the name of your local database. Provide additional username and password fields if you're using SQL Server authentication. If you're using Windows Authentication specify it.
Example string for SQL Server Authentication:
<add name="YourEntities" connectionString="*your metadata link*;provider=System.Data.SqlClient;provider connection string="Data Source=**your server name**;Initial Catalog=**your database name**;User ID=**your username**;Password=**your password**; MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Just change the values of the attributes data source, initial catalog, username and password.
For windows authentication:
Add the following attribute:
Integrated Security=True;
and remove attributes username and password.
How can I create a SQL user in a SQL Server Express database that I added to my project?
I need to create a user to use in a connection string that doesn't use Integrated Security.
You would need to create a SQL Authenticated login first with CREATE LOGIN then add a user associated with that login to your database by using CREATE USER.
USE [master]
GO
CREATE LOGIN [JohnEgbert] WITH PASSWORD=N'YourPassword',
DEFAULT_DATABASE=[YourDB], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [YourDB]
GO
CREATE USER [JohnEgbert] FOR LOGIN [JohnEgbert] WITH DEFAULT_SCHEMA=[dbo]
GO
If you create a SQL login and a SQL user without errors, but then get an error when trying to connect, you may have the SQL Authentication mode disabled. To check, run:
SELECT SERVERPROPERTY('IsIntegratedSecurityOnly')
If this returns 1, then SQL Authentication (mixed mode) is disabled.
You can change this setting using SSMS, regedit, or T-SQL:
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2
Then restart the SQL Server service, and create a login and a user, here with full permissions:
CREATE LOGIN myusername WITH PASSWORD=N'mypassword',
DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
EXEC sp_addsrvrolemember 'myusername', 'sysadmin'
CREATE USER myusername FOR LOGIN myusername WITH DEFAULT_SCHEMA=[dbo]
I have developed a c# program I want to use to access a remote server from a client computer on the same domain.Every time I try to connect to the database I am getting an error login failed for user domain\myclientusername
Using the connection string below:
<add name="dbname" connectionString="Server=remoteservername;Database=dbname;Integrated Security=True;"/>
I have already checked and the server is set to allow remote connections. I am able to log on to the server using admin credentials do I need to set the connection string to use admin password and user name to connect to the database? or do I need to add my client profile credentials to the database permissions. Very new to deploying applications.
You will need to set up access to the database for the connecting user/client PC. You sort of "map" a user on the domain to a SQL user or group
Go to SQL management studio> connect to your database> expand databases > expand 'security' and then 'logins'
right click logins and select new login. search for the user of the connecting user/client PC. Then under the "user mapping" tab you can give access to the specific database. it may be best to give "db_owner" at first just to ensure you have the connection. after that, you should limit the access to only what is needed.
you can always check the SQL events log from the SQL machine itself and see what the specific authentication issues may be. go to "Events" in the Administrative tools (which is in control panel) and you can see SQL specific events.
Either you can remove the Integrated Security=True in your connection string and insert the username and password of a Login you create in you SQL Server database to your connection string.
Or, you can create a login for the user under which your c# program is running (yourself - for testing, domain service account under production) to the SQL Server and give it appropriate read/write access.
More information on connection strings: http://www.connectionstrings.com
More information on how to create login in SQL Server : http://msdn.microsoft.com/en-us/library/aa337562.aspx
When you set Integrated Security=True , the current Windows account credentials are used for authentication.
Since you are trying from a different PC than the one that is running the SQL instance it is much likely the acount you are trying to connect with differs from the acount registered to the instance log in.
what you can do is:
Use Integrated Security=sspi and provide the login credentials, e.g:
connectionString="Server=remoteservername;Database=dbname;User id= myUser; Password=myPass;Integrated Security=sspi";
you can also set Integrated Security=false and also provide the credentials, (but the connection won't be using Windows Athentication)
IN localhost insert statement WORKS PERFECTLY ( insert data in database sql management server) but from web server it doesn't ( update, delete works but not insert).
I am using sql connection , string str = insert into dtbase.dbo.candidat values ().
command cmd = new command (sql, connection)
Can someone please tell me why it doesn;t work from wb server ( I am using web application.) do i need to add some permision in web.config?
To determine if this is a permissions issue (which I think it is) or not then temporarily (this is for the down voters out there) enable ASP.Net Impersonation by using an account that you know has access to your network and SQL Server instance: http://support.microsoft.com/kb/306158
Based on the other comments, I agree that it sounds like a permissions issue.
You may be getting the error using database.dbo.table because your table was created under a different schema (ie. database.user.table) and you're trying to access that schema from a user that doesn't have permissions to that schema.
Does your connection string change from localhost to your production server?
I am using SQL Server Express 2005.
I have a single database myDB
I have created a Login L-1 with user U-1 on databas myDB.
To connect to database myDB I found 3 ways:
-1(a)-after creating L-1 Login with default database = myDB , I have to create a user U-1 , and when I connected to SQL server , then it connected.
I used this query:
create login L-1 with password='passL1' , default_database = myDB
use myDB
create user U-1 for login L-1
Means, creating a user inside a login , gives the user connect permission implicitly. Am I right ?
-1(b)-I didn't create any user U-1, but executed this :
use myDB
sp_grantdbaccess L-1
this also made me connect , the reason being that, sql added a user named L-1 implicitly in the myDB database. Am I right?
-1(c)-this time also, I didn't create any user U-1,but I executed this:
sp_changedbowner L-1
this also made me connect , the reason being that, sql added a user named L-1 implicitly in the myDB database. Am I right?
Now, I want to give the user U-1 created in 1(a) the following permissions:
Create Logins L-2,L-3
Create Users U2,U3 which can also connect to database myDB.
How do I do this?
Yes - calling sp_grantdbaccess or sp_changedbowner will just implicitly do what you would normally do with CREATE USER - no difference.
Calling CREATE USER explicitly is just clearer, more obvious what you're doing etc.
Also: don't use sp_grantdbaccess anymore - because:
This feature will be removed in a
future version of Microsoft SQL
Server. Avoid using this feature in
new development work, and plan to
modify applications that currently use
this feature. Use CREATE USER instead.
Source: Technet on sp_Grantdbaccess
And don't use sp_changedbowner either - same reason:
This feature will be removed in a
future version of Microsoft SQL
Server. Avoid using this feature in
new development work, and plan to
modify applications that currently use
this feature. Use ALTER AUTHORIZATION
instead.
Source: Technet on sp_changedbower