Open Connection, Connection String, what's my database name? - sql

I've been given a VBcode by my company to work on.
I have an SQL file that I have to run in order to create the tables in my database.
The connection string that I have to open a connection with on my vb.net is the following:
"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Test;Data Source=DATOR06"
I need to know what the name of their database is so I can create something similar in my own local PC.

In the connection string Initial Catalog represents the Database name.
in your case "Test" is your database name.

It's under Initial Catalog=Test so in your instance the Database name is Test and the DataSource is DATOR06.

Initial Catalog=Test
Test is the database name, in connection string Initial Catalog represent the db name.

Initial Catalog tells you the name of the database, in this case is Test

Related

SQL code not running , getting a "permission denied for schema public" error message

CREATE TABLE student
(
student_id INT PRIMARY KEY,
nam VARCHAR (20),
major VARCHAR (20)
);
I'm just running this code and I keep getting a permission denied for schema public message. What does this mean and how can I fix it.?
I see you are asking this in reference to the freeCodeCamp's SQL course by the looks of it.
You need to create your own database and you should be good to go, see the steps below:
Open mySQL command line and create a new database CREATE DATABASE TestDB
Open PopSQL > File > Preferences > Connections > Add New Connection > MySQL
Connection name: any name
Hostname/Port: localhost | 3306 (3306 is default port number, maybe you used/have different port during MySQL installation)
Database: TestDB
Username: root | Password: (this is what you set when you installed MySQL)
Connection Type: turn this ON, you want to "Connect directly from my computer"
Test connection, if successful, save.
Also, please note this is working on MySQL Server 5.7.20, it may be different on other versions.
It means you are using POPsql sample data. Click on manage connections and add a connection to your own database.
Please make sure you are using the right database, in the popSQL the "PopSQL Sample Data" database is selected by default.
you can change it as mentioned below
You need to add your own new connection instead of running it on POPsql sample data private connection
just delete the other sample server from the list of connections and add your own.
I see you are asking this in reference to the freeCodeCamp's SQL course as the same with me, what you really need to do is make sure you follow all of his instructions and after that make sure you change the connection to MySQL after add the new connections.
enter image description here

Hard code credentials in MS Access connection string (password protected)

I want to hardcode the credentials for connection to an Access database.
My connection string currently looks like
$strConn = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = $dbName;
And this works fine, but I am prompted to enter a "User Name" and "Password". I have researched Access connection strings, but I can only find one that includes password (not user)
$strConn = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:Database Password=Your_Password"
I have tried using this (as well as combinations of user/username/uid etc) but have not found anything that works.
Here is the window that is popping up (service name is automatically populated):
Looks similar to this: Oracle ODBC Driver Connect always asking for password
I believe it has something to do with the Access database being linked to an oracle database. Is this out of my hands?
You can get direct access to a linked table by using its connection string, and filling in the user and password. For Oracle, the connection string structure can vary upon the used provider. View ConnectionStrings.com for a list of options (most likely option is Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=myUsername; Password=myPassword;).
You can obtain the current connection string for the linked table by querying MSysObjects inside Microsoft Access:
SELECT MSysObjects.Connect
FROM MSysObjects
WHERE MSysObjects.Name="MyLinkedTableName";
You can even change the connection string to include your username and password, if you wanted (see this answer).
However, take note that the one who originally linked the tables in Access, chose not to include a username and password. Including a username and password in an unsecured Access database might pose a security risk.
Also, take note that if you connect directly to the Oracle database, you must reference the table names as defined there, and use the proper SQL variant to query it.
According to the handy reference page ConnectionStrings.com, pass User Id=<username> and Password=<password> like so,
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;
Password=Pa$$w0rd;

Connect to Database server-side

I've essentially made a MVC application following the tutorial at http://www.asp.net/mvc/tutorials/getting-started-with-mvc3-part1-cs
I can upload it to a server and have the main page run just fine.. but running a different page that interacts with a database brings up the error
" Invalid object name 'dbo.Lyrics'. "
Now I can connect to the database that I'm trying to use (on the server) remotely using management studio just fine.. its called Lyrics and the table is Default.Lyrics ..
The connection string I'm using is "connectionString="Data Source=74.86.97.85;Initial Catalog=Lyrics;User Id=Default;Password=****;""
So my question is .. why is my application trying to use an object with the name "dbo.Lyrics" when my entire application doesn't have that text in it? How can I solve this?
I know that the dbo prefix means DataBase Owner.. and its like a public table.. but since I'm specifying a User ID shouldn't it look for tables with my ID as the prefix?
dbo at the beginning of an object name is a schema. Schemas partition the objects in your database. dbo is simply the default schema.
So, if you have an object named Lyrics, then it's really dbo.Lyrics.

How to create Sql Synonym or "Alias" for Database Name?

I'm using ms sql 2008 and trying to create a database name that references another database. For example 'Dev', 'Test', 'Demo' would be database names that i could reference from my multiple config files, but each name would point to another database such as 'db20080101' or 'db20080114'.
[Edit]Some of the configs are for applications that i control the code and some aren't (ex. MS Reporting service datasource file configs)[/Edit]
It seems that sqlserver only supports synonyms for View,Table,Sproc, or Function. And Alias' are for table and column names.
Is there a way to do this that i missed in the docs?
Any one have any suggestions on a workaround?
use 3 part notation and alias up to the table, example
select * from tempdb.dbo.sysobjects a
join master.dbo.sysobjects b on a.id = b.id
There is a way to simulate this using a linked server. This assumes you have two SQL servers with the same set of databases one for development/test and one live.
Open SQL Server Management Studio on your development/test server
Right click Server Objects > Linked Servers
Select New Linked Server...
Select the General page
Specify alias name in Linked server field - this would normally be the name of your live server
Select SQL Native Client as the provider
Enter sql_server for Product Name
In Data Source specify the name of the development server
Add Security and Server Options to taste
Click OK
The above is for SQL Server 2005 but should be similar for 2008
Once you've done that you can write SQL like this:
SELECT * FROM liveservername.databasename.dbo.tablename
Now when your scripts are run on the development server with the linked server back to itself they will work correctly pulling data from the development server and when the exact same scripts are run on the live server they will work normally.
I've done something similar to this using another config file.
The new config file maps your generic name to all of the information needed to connect to that database (db name, user name, password, etc.) and then your connection function takes your generic name as an argument.
db.config:
DEV_DB_NAME = db20080101
DEV_DB_USER = dev_user
DEV_DB_PASS = dev_pass
TEST_DB_NAME = db20070101
TEST_DB_USER = test_user
TEST_DB_PASS = test_pass
connection code:
db_connection get_connection(string prefix) {
db_connection db_conn = new db_connection;
string db_name = get_config_value(config_path, prefix + "_DB_NAME");
string db_user = get_config_value(config_path, prefix + "_DB_USER");
string db_pass = get_config_value(config_path, prefix + "_DB_PASS");
db_conn.connect(db_name, db_user, db_pass);
return db_conn;
}
Then you just call get_connection() with your db alias as the argument.
I know this probably will not help in all situations, but you still have the option of using views. You can insert, delete, update, select into a view as long as it has a proper identity key (Primary Key). If you point it to another database, you should drop and recreate to get the different schema (in case you're working between production and test while making changes to the schema in test and/or production.
Synonyms are useful for when you're going to another database and have a 3 or 4 part name, but when you want to make it so you can have a set name, a linked server will also work which will let you use a fixed name if the table names are the same in both databases and you're just pointing between prod and test.

Accessing 'Global' Variables In An ExecuteSQL Task

I have an SSIS package that does the following:
Selects the connection strings from a table of servers. The connection string is either the name of the server along with the domain (i.e. Dalin.myhouse.com) or is the direct IP to a server.
The package iterates through each connection string and populates a defined 'global' variable. This variable was created with in the Variable designer. For each connection string, the package will retrieve information about the server.
The problem I'm having is when you add a server IP to the list, the 'Friendly Name' may not be known at that time so I would just have the server IP in both the connection string column and the friendly name column of the table. I want to, after the end of an iteration, update that the Friendly Name column of the server entry within that table so that it has the server name pulled from the server using SERVERPROPERTY('Servername')
To do this, I would like to use an ExecuteSQL Task with the following code:
UPDATE [myDB].[mySchema].[myServers]
SET [ServerName] = VarA
WHERE ConnectionString = VarB
The previous code is using a static connection to the server where the myServers table resides.
VarA represents the global value I want to set the ServerName to which would be set in a separate SQLTask by using SERVERPROPERTY('Servername'). It needs to be in a separate task because it would have to connect to a server by using the same server the current iteration is using.
VarB is set at the beginning of every iteration to the next Connection String in the list.
I've seen examples on how to use this for the Script Task and Script Components but I would like to simply use the ExecuteSQL Task to accomplish this.
Summary:
Connect to ServerA and fill two global variables.
Connect to ServerB and use the two global variables to update a specific row in a table.
Any ideas?
I can't see how this can be accomplished without the variables being set within a Script Task, since ExecuteSQL tasks have to be set to a database connection. Script Tasks work for this because their connection is within the context of the server that's executing them. That being said, you could use a Script Task prior to this ExecuteSQL task that sets the variables to the local server instance.
So you need the Execute SQL task to take parameters?
http://msdn.microsoft.com/en-us/library/ms187685.aspx
Maybe I've misunderstood...