This is the continue topic with this topic:
Oracle 10g: Error when creating database manually by scripts
Basically, I had created an Oracle database named "testdb" using only batch scripts and SQL scripts.
After successfully creating a database using script, I create a script to create user for client connect to the database.
CreateUser.bat
sqlplus sys/test as sysdba #D:\Script\CreateUser.sql
CreateUser.sql
shutdown immediate;
startup;
CREATE USER usr1 IDENTIFIED BY usr1
DEFAULT TABLESPACE users
QUOTA UNLIMITED ON users;
GRANT CREATE SESSION, GRANT ANY privilege TO usr1;
exit;
Everything run ok, with no error.
Then I try to test by connecting to SQLPlus on cmd:
sqlplus usr1/usr1#testdb
This retrun the error:
ORA-12154: TNS:could not resolve the connect identifier specified
I wonder what I did wrong.
The same happen for the database I created via DBCA.
The error is because you don't seem to have an entry for testdb in your tnsnames.ora file. You could add one, manually or with the configuration tools netca etc); or you could bypass that with the 'easy connect' syntax:
sqlplus username/password#//hostname:port/service_name
If this is on your local machine, the default port and the service name matches the SID, that could be simolified a bit to:
sqlplus usr1/usr1#//localhost/testdb
You can verify the service name in v$parameters, or with lsnrctl services.
You can read more about connections and naming methods.
If your are connecting to a database on the same machine as the client, and you are using the same ORACLE_HOME, you don't need to use TNS/SQL*Net at all. With ORACLE_SID set to the right value, just doing this will connect locally:
sqlplus usr1/usr1
you can sqlplus usr1/usr1#testdb when you create connect string. It means that you need to entry in tnsnames.ora file
Related
I am creating a CI/CD pipeline to run my application, In my application it has multiple databases like database1, database2 ..... previously I was using AWS aurora Postgres , now I want to check the compatibility of the application with oracle RDS. Well, I don't know much about the oracle. I got to know that we can create multiple schemas
My application has 7 databases with a different names and in CI/CD pipeline I am using SQL plus to connect to the database and created all schemas, but I don't know how can I connect to a particular schema
I was able to connect to a database that I specified when creating Orcale RDS using:-
sqlplus username/password#oracle.xxxxxx.us-east-1.rds.amazonaws.com:1521/demo
I have used the following command to create the schema:-
CREATE BIGFILE TABLESPACE database1 DATAFILE SIZE 128M AUTOEXTEND ON NEXT 1M
MAXSIZE unlimited LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
create user database1 identified by database1 profile default default tablespace
database1 TEMPORARY TABLESPACE TEMP ACCOUNT UNLOCK;
GRANT create trigger, CONNECT, RESOURCE, create table, create view, create
procedure, create sequence TO database1;
after that, I am running SQL plus command to connect to database1and it is not working
sqlplus username/password#oracle.xxxxxx.us-east-1.rds.amazonaws.com:1521/database1
Just wanted to is there any way to connect to a particular schema as my application is using jdbc:oracle:thin to connect to the database
In Oracle, schema = user ("create user database1 ..."), so what you're looking for is this:
sqlplus database1/database1#oracle.xxxxxx.us-east-1.rds.amazonaws.com:1521/demo
'demo' is actually the network service name, which will be the same for all users/schemas within the physical database instance.
I am creating a spring boot application which is connecting to an Oracle DB instance.My application is required to process SQL commands like CREATE PLUGGABLE DATABASE,ALTER PLUGGABLE DATABASE,ALTER SESSION,CREATE TABLESPACE,ALTER USER etc.
My Application.properties is as below
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:#x.x.x.x:port/servicename
spring.datasource.username=sys
spring.datasource.password=somepassword
Since ALTER PLUGGABLE DATABASE COMMANDS require sysdba privilege to execute,I've given the sysdba user "sys" and its password in the application.properties file.
However when I execute the command,I get the error
"connection as SYS should be as SYSDBA or SYSOPER".This user has the sysdba privilege ,however when I run from SQLPLUS I mention
SQLPLUS / as sysdba before executing the alter commands.
I have tried specifying
spring.datasource.username=sys as sydba,
however that results in an ORA-01017: invalid username/password; logon denied error.
Can you please suggest how I can connect as sysdba from my application and execute the alter commands?
Note:I just heard that it is not possible to connect as "sys" from an application,if so could you please suggest what type of user and what privileges would be required for an user which can be connected from application to execute ALTER PLUGGABLE DATABASE commands
Note 2:My application itself is designed to create and alter PDBs based on JSON inputs.Its not an one time task to be done by a DBA.
I use spring boot framework and oracle 12c (database).
my application.properties file look like this:
# ===============================
# = DATA SOURCE
# ===============================
# Set here configurations for the database connection
spring.datasource.url=jdbc:oracle:thin:#127.0.0.1:1521:ORCLCDB
spring.datasource.username=sys as sysdba
spring.datasource.password=Oradoc_db1
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
# ===============================
# = JPA / HIBERNATE
# ===============================
# Show or not log for each sql query
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
# Naming strategy
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
you have to specify the username in this way:
spring.datasource.username=sys as sysdba
you could find the file here
username: SYS as SYSDBA
Works for me
I just installed Firebird for Win64, and I was trying to connect to the employee database which comes pre-packaged with ISQL.
Following the steps from the Firebird official QuickStart Documentation I opened the ISQL utility and entered:
connect localhost:employee user sysdba password masterkey;
As a result I got:
Statement failed, SQLSTATE = 28000
Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
Strangest thing is that if I navigate to the employee database sample itself and issue the isql command from there I can successfully connect.
The difference is that connecting directly to a database file doesn't require a password, it will even ignore the password, and just use the provided user to know which privileges to apply.
Without a hostname, ISQL will by default use Firebird embedded mode, and not the server. To compare, try using isql employee.fdb (or isql employee), it will just login with your current OS username, while isql localhost:employee will fail with a 'Your user name and password are not defined'.
It looks like you specified a different password than the default of masterkey, or somehow the sysdba account wasn't initialized. I recall there was a problem with the installer of an earlier Firebird 3 version, but I don't think 3.0.2 should be affected by this (or at least: it worked for me).
If the SYSDBA account wasn't initialized, then follow the steps of the Firebird 3 release notes, section Initializing the Security Database:
Initialization Steps
Initialization is performed in embedded mode using the isql utility.
For an embedded connection, an authentication password is not required
and will be ignored if you provide one. An embedded connection will
work fine with no login credentials and “log you in” using your host
credentials if you omit a user name. However, even though the user
name is not subject to authentication, creating or modifying anything
in the existing security database requires that the user be SYSDBA;
otherwise, isql will throw a privilege error for the CREATE USER
request.
The SQL user management commands will work with any open database.
Because the sample database employee.fdb is present in your
installation and already aliased in databases.conf, it is convenient
to use it for the user management task.
Stop the Firebird server. Firebird 3 caches connections to the security database aggressively. The presence of server connections may
prevent isql from establishing an embedded connection.
In a suitable shell, start an isql interactive session, opening the employee database via its alias:
> isql -user sysdba employee
Create the SYSDBA user:
SQL> create user SYSDBA password 'SomethingCryptic';
SQL> commit;
SQL> quit;
To complete the initialization, start the Firebird server again. Now you will be able to perform a network login to databases,
including the security database, using the password you assigned to
SYSDBA.
Where 'SomethingCryptic', should be your password.
If a SYSDBA user was created, you will need to change its password if you no longer remember what you set. Follow the same steps, but in step 3 do:
SQL> alter user SYSDBA set password '<new password>';
SQL> commit;
SQL> quit;
If this gives an error "record not found for user: SYSDBA", make sure you are really connected as SYSDBA, otherwise retry the original step 3. Not having admin access will behave as if the user doesn't exist, so the error is the same if the user really doesn't exist, or if you are connected with an unprivileged user.
CONNECT 'employee' user 'SYSDBA' password 'masterkey';
You need make sure that your alias.conf have something like this: employee=C:/examplepath/employee.fdb
make sure that the services of firebird is on
I am getting access denied errors when I move files from server1 to server2. Please advise how I should get past this error in my tsql script.
I used xp_cmdshell 'move d:\files \server2'
tsql uses the permissions of the account used to start the SQL Server instance. To see the account used, open the services control panel, locate the SQL Server service, goto properties and then logon tab. You probably need to change this to an account that has the appropriate permissions.
I'm logging in to create a new database from CMD through sqlcmd with SA account. Its response is a message: CREATE DATABASE permission denied in database 'master'.
I'm using Windows server 2003 and SQL 2008. Please help me. Thanks in advance.
It doesn't sound like you're actually using the sa account, or else perhaps you haven't set up your service account properly using SQL config mgr. If you used Computer Manager | Services, then the service might not have permission to create the database files.
...Run As Administrator should do the trick.
Typically the user you're using to run the SQL Server service will not have access to certain folders, which is likely why you're getting this error.
Consider one of these alternatives:
change the credentials used for the service (ick!)
use runas /u:... or Run as...
add permission for the service to access those folders
move the database to a location that the service can access
I would check whether the user you are using indeed has CREATE DATABASE permission though. You can check what server roles it belongs to, because it seems it is not a sysadmin role.
You can use this query for example.
select suser_name(role_principal_id) [login ...],
suser_name(member_principal_id) [... belongs to]
from sys.server_role_members
Regards
Piotr