Permissions Issue on SQL Server 2008 - sql-server-2008

I have just moved a database from our test server to the live server by creating an empty database and restoring a backup to it.
Despite adding the Login correctly, I am getting the following error:
The server principal "myUser" is not able to access the database
"myDatabase" under the current security context.
I have tried clicking F7 in Object Explorer Details with no luck. I can get the error simply by running:
> USE myDatabase
> GO
>
> EXECUTE AS LOGIN = 'myUser'
Running the following script (from a related question) shows the user correctly
select princ.type_desc
, princ.name
, perm.permission_name
, perm.state_desc
, object_name(perm.major_id)
from sys.database_permissions perm
left join
sys.database_principals princ
on princ.principal_id = perm.grantee_principal_id
SQL_USER myUser CONNECT GRANT
Any suggestions???

Try using sp_change_users_login with the "Auto_Fix" action to resync the logins between the server and the database.
exec sp_change_users_login #Action = 'Auto_Fix', #UserNamePattern = 'myUser'

Related

SELECT command denied to user '<userid>'#'<my-pc-ip-address>' for table '<table-name>'

I get this error when I'm using post man for get response from my API.
java.sql.SQLSyntaxErrorException: SELECT command denied to user '<userid>'#'<my-pc-ip-address>' for table '<table-name>'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.16.jar:8.0.16]
but I can use SELECT Statement perfectly in Workbench with the same user.
application.properties
spring.datasource.url = jdbc:mysql://<database.ip>:3306/<database.schema>
spring.datasource.username = test
spring.datasource.password = test123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
I'm trying to using root account but I get this error
java.sql.SQLSyntaxErrorException : Unknown database '<db_name>'
I can solve this issue with this
replace
#Table (table = "tablename") instead
#Table(table = "tablename", catalog = "catalogname" schema)
place this thing to application.properties
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
The user "test" is not granted to access the database.
You have to grant it first
Please find the grant command in the manual
https://dev.mysql.com/doc/refman/8.0/en/grant.html
Just like Simon says above, the user 'test' doesn't have the right privileges to perform a 'SELECT' operation.

error on starting grafana service

I have grafana 4.4.3 on an ubuntu 16.4 LTS which is installed on an vm and its IP is 1.2.3.4 .
I also have a mysql database version 5.0.95 on a CentOS 5.9 and its ip is 5.5.5.5 and mydatabase name is : voip
I want to set mysql as backend for grafana. I'v changed my grafana.ini file like this:
###[database]###
type = mysql
host = 5.5.5.5:3306
name = voip
user = root
password = t#123
###[session]###
provider: mysql
provider_config = `root:t#123#tcp(5.5.5.5:3306)/voip`
I also set my root account to be used as a remote account.
when I want to start grafana-server service, it gives me this error:
Fail to initialize orm engine" logger=sqlstore error="Sqlstore::Migration
failed err: this user requires old password authentication. If you still
want to use it, please add 'allowOldPasswords=1' to your DSN. See also
https://github.com/go-sql-driver/mysql/wiki/old_passwords\n"
what should I do? Did I don anything wrong?
allowOldPasswords error is given when you are using old version of mysql database. to change this you should go to /etc/my.cnf and change oldpasswords = 1 to oldpasswords = 0. next you have to login to your mysql and then enter these commands:
SET SESSION old_passwords=FALSE;
SET PASSWORD FOR 'user_name'#'%'=PASSWORD('<put password here>');
flush privileges;
and at last, restart your mysql service.
hope this post is helpful...

nodejs connect to mysql DB "INSERT command denied to user"

I want to connect mysql DB and insert some values into the table. But I get the result: "INSERT command denied to user '' #'localhost' for table 'paramenttable'".
DB connection page
(to call the two function in route.js like this:)
mysqlinsertp.conn();
mysqlinsertp.insert(array_1);
the error page:
The config for mysql could not be found in that variable. The module exports of settings.js provide a mysql item. You should use that instead of the root.
Your client initialization should be following:
var client = mysql.createConnection(settings.mysql);
instead of mysql.createConnection(settings);

How do you use SQLCMD to login to SQL Server Express, user no password set

I installed SQL Server 2012 Express and I'm learning from a book on SQL Server administration. My task is to write a batch file to copy data from a table and export it to an Excel spreadsheet.
I've got the instance name right and my username but log in fails because of password. When I enter Management Studio and click connect I see my username but password is blank, I successfully connect to my databases this way. How do I set a password for my account? I think I can't log in using SQLCMD because I don't have this set. My username is the same as my windows username, using the password that I log on to windows with doesn't work.
SQLCMD -S CRAIG-PC\SQLExpress -U CRAIG-PC\Craig -P *********
-d AdventureWorks
-Q "SELECT * FROM Sales.SalesOrderDetail" -o C:\ExportDir\export.csv
This is the command in the batch file that I'm trying to connect and query the database. If I take out -P ******* SQL Server is waiting for a password. If I don't use a username or password connection is refused.
Remote connections are enabled using tcp, but this is a local install.
Use the '-E' switch to make your connection a trusted (Window's authentication) one, then you don't need user name and password at all (provided you have sufficient rights on your machine)
http://technet.microsoft.com/en-us/library/ms162773.aspx
Note in my python code below, I don't implement the user or password.
Hope that helps
_query = "CREATE DATABASE %s ON (FILENAME = '%s'), (FILENAME = '%s') FOR ATTACH;" %(_database, mdffilepath, logfilepath)
command_process = SubP.Popen(['sqlcmd','-b', '-E',
'-S', _server,
'-d', 'master',
'-q', _query],
stdin = SubP.PIPE,
stdout = SubP.PIPE,
stderr = SubP.STDOUT,
shell = True)
_stdOut, _stdError = command_process.communicate()
Check the name of the database, ie "AdventureWorks" should be "AdventureWorks2012"
sounds like you are using windows authentication you can remove the -u and -p. when those are not provided sqlcmd will use windows authentication.

can't create database by xampp mysql command window

When I try to create a new database(m) in xampp mysql command window then I'm getting an error message
"ERROR 1044 (42000): Access denied for user ''#'localhost' to database
'm'".
Then I created that database by using phpmyadmin but its not shown in mysql command window when I type show databases command there. Can anybody tell me how can I get rid of that error message and can successfully create new database by using mysql command window in xampp? (I'm using windows xp professional service pack-2)
-Thanks.
Are you logging as a root?
Browse to the mysql.exe containing foler and try typing this in the cmd:
mysql.exe -u root --password
Try to initiate your mysql client with a specific username and password ( if you have set one )
mysql.exe -uroot [-p]
Edit:
Add this to your my.cnf [client] section to log-in without any parameter
[client]
user=root
http://dev.mysql.com/doc/refman/5.5/en/mysql-command-options.html
RESOLVED:** Thanks to all for your kind replies. I solved that problem.
I changed the 'user' table in 'mysql' database by using phpmyadmin and set the fields to 'Y' while those were 'N' where host was 'localhost'(so localhost wasn't able to create or drop any database).Now its possible to create new database by 'xampp\mysql\bin\mysql.exe'.
AND **to get .frm(table definition), .MYD(table data) and .MYI(table indices) files for a table in mysql data folder,I SET type=MyISAM and collation=utf8_general_ci so it would be easy to copy the database to another pc or server.
I know you've solved the problem .I had the same problem ,but the answer is simple .Answer :if you type "localhost" in your browser ,after selecting the language , you can select "phpmyadmin" .then as you said you can click on the "Databases" tab ,then from the list of databases select "mysql" and eventually you can see that the last table of this database is "user" table.if you then click on the "browse" button right in front of the name of the table which is "user". now you can see the "user" table in detail.you can see under the "host" column there are 3 "localhost" cells ,but only one of them has value of "root" in the "user"
column which is the next .so if you want to connect mysql via command prompt , if you have not set password yet ,( c:\xampp\mysql\bin\mysql.exe -u root ) not
( c:\xampp\mysql\bin\mysql.exe ) or not ( c:\xampp\mysql\bin\mysql.exe -u root -p ) .