analysis services datasource migrated - ssas

I have none experience with SSAS, I had this cube working perfectly…
The underlying tables that it was using were from a database, let’s call it ‘ABCD’. The problem is, that for other reasons ABCD database had to be split in ‘AB and ‘CD. Half the tables have been migrated to AB and the other half to CD. In my mind I want to open something as ALTER, edit the DB name, and everything would work as before, but SSAS is a bit of a black box for me; can I achieve this?
I know I can just access ABCD and create views to AB and CD and mask my problem, but I would really love to know how to modify the scripts that build the cube….

My recommendation is to just add views into the AB database which point to the tables which have moved to the CD database. Then you can edit the data source from Management Studio and point it to the AB database. (You just connect Object Explorer to Analysis Services, expand down to the database, expand to the Data Source, then double click to edit.)
If that's not an option then you can change the cube source code as follows...
I'm assuming it's a Multidimensional cube, not Tabular. If you already have Visual Studio and SSDT installed, great. Otherwise, install the latest SSDT which runs in Visual Studio 2015 as it's backwards compatible.
In SQL Server Management Studio, connect Object Explorer to Analysis Services and then right click on the database and choose Backup.
In Visual Studio, File... Open... Analysis Services Database. You are editing the cube "source code" live now. As soon as you save a change it will deploy it to the server.
Double click the data source and fix the connection string. Make sure it's using a version of the driver that's on the SSAS server. Point it to the AB database.
Then double click the DSV. In the tables list on the left, right click on each table which was moved to the CD database and choose Replace Table... With New Named Query. Click the "Switch to Generic Query Builder" button and then edit the query to look something like:
select *
from CD.dbo.YourTable
Click Save.
Then go back to Management Studio, right click the database and choose Process. Do a Full Process on the database. It should succeed and be up to date.
It is possible to reverse engineer a deployed SSAS database. The above assumes that's not important to you. But if you need to do this, in Visual Studio do File... New Project... Templates... Business Intelligence... Analysis Services... Import From Server (Multidimensional and Data Mining).

Related

Creating a local database from server database in visual studio

I have a rather large database I am working with and I am about ready to break something. To prevent this affecting live data, how would I use the live database to setup a local database? Not sure if this is even possible but I do know you can setup a local db.
You can create a SQL Server Data Tools database project type, then right click the project file and do an "Import..." to import the database to your local machine. Then you can deploy the local DB and it will be available in the SQL Server Object Explorer locally. This way you don't have to install SQL server on your machine - everything's in Visual Studio. Hopefully you are developing with a small set of data locally.
Answer
Use Visual Studio's Data Comparison tool to synchronize data to your target database from your source after you've created the database (schema only, no data) in your local database server.
Steps
From the Visual Studio's SQL Server Object Explorer:
A. Create the local database
Add two SQL Server Objects: One that connects to your production server and one that connects to a local (development/testing) server. If you need help setting up a local server then take a look at SQL Server LocalDB
Add a New database in your local server to receive the data (don't over think this step).
B. Migrate the Schema
Right-click the source (production) database and click Schema Compare...
From the SQlSchemaCompare tab that opens, use the Select Target dropdown to select your local database as the target.
From the SQlSchemaCompare tab, click Compare.
Uncheck everything in the comparison results except for the Tables, Views, and Procedures (unless you know what you're doing) then click Update.
C. Migrate the Data
Right-click the source (production) database and click Data Comparison...
Follow through the prompts to select the Tables to migrate then click Finish.
From the SQlDataCompare tab that opens, review the comparison results (it should make sense to you) then click Update Target
That's it! Either your local database is ready with data, or you confused your target/source and wiped out all of your data in production. Either way, you're done for the day.

How to change the connection in Sql Server Data Tools Editor in Visual Studio

My goal is to keep SQL Server stored procedures under source control. I also want to stop using SQL Server Management Studio and use only Visual Studio for SQL related development.
I've added a new SQL Server Database project to my solution. I have successfully imported my database schema into the new project, and all the SQL objects (tables, stored procedures) are there in their own files.
I know that now if I run (with F5) the .sql files then my changes will be applied to my (LocalDB). This if fine, but what if I want to very quickly run something on another machine (like a dedicated SQL Server shared by the entire team)? How can I change the connection string of the current .sql file in the Sql Server Data Tools editor?
I have the latest version of Sql Server Data Tools extension for Visual Studio 2012 (SQL Server Data Tools 11.1.31203.1). I don't know if this is related to the current version, but I cannot find anymore the Transact-SQL Editor Toolbar.
I have also tried to Right-click on the sql editor, choose Connection -> Disconnect. If I do the reverse (Connection -> Connect...) the editor directly connects automatically (probably to my LocalDB), without asking me a dialog to choose my connection.
Another strange thing I've observed, if I try to run a simple SQL query (like select * from dbo.ApplicationUser I receive the following message (even if the autocomplete works):
Thanks.
(Note: I have the same issue with Visual Studio 2013)
Inspired by srutzky's comments, I installed the latest SSDT pack (12.0.41025). And bingo, like srutzky said there is a Change Connection option. But what's more, you can specify your Target DB by right clicking on the Project in the Solution Explorer, and going to Properties->Debug and changing the Target Connection String! If you're stuck on an older SSDT, then the below instructions will still work.
For SSDT 12.0.3-
I've also been plagued by this problem! My solution is below, but it has some Pros and Cons to it...
SOLUTION
I'm assuming that you are using a SQL Server Project in VS (I'm using VS2013 and SQL Server 2012).
Right click on your .sql file in the Solution Explorer and view Properties.
Change Build Action to None.
If the file is open for editing, then close it.
Reopen the file, and the T-SQL Editor should appear at the top.
Click Connect, and you will connect to your (localdb).
Click Disconnect.
Click Connect again and the SQL Server Connection dialog should appear.
Switch the connect string of '(localdb)\Whatever' to '.' (for some reason using '(localhost)' didn't work for me).
Voila, you should now be able to query against your SQL Server DBs! Rinse and repeat for every file you want this capability with... :/
PROS
You can finally run queries directly against your SQL Server DB
Your code can be organized in a nice VS solution (SSMS doesn't allow folders! :/)
You can (after switching Build Action setting back) Build the project
CONS
I'm not seeing any autocomplete/intellisense against the remote DB, although if you import your DB, then you could gain the intellisense from that
Requires each file to switch Build Action to None
This should be a fairly simple and straight-forward thing to do, that is, if you are using SSDT version 12.0.41025.0 (or newer, one would suppose):
Do either:
Go to the SQL menu at the top of the Visual Studio window
Right-click inside of the SQL editor tab
Go to Connection ->
Select Change Connection
Then it will display the "Connect to Server" modal dialog window.
If you do not see the options for "Disconnect All Queries" and "Change Connection...", then you need to upgrade your SSDT via either:
Visual Studio:
Go to the "TOOLS" menu and then "Extensions and Updates..."
Direct download:
Go to: http://msdn.microsoft.com/en-us/data/tools.aspx
The fastest way to achieve this is create a new SQL Connection, copy and paste the code then execute.
What I do is Tools->SQL Server->New Query.
Enter the database credentials (And make sure that the Database at the top is correct - I have hundreds of sp's in my master db on local :) )
Copy the source code from the editor, paste into the new query window.
Then Execute (CRTL-Shift-E).
You can leave this 'scratch' window open and pinned for easy access for subsequent executes.
If you want to deploy (i.e. publish) the entire database then you can setup a publish destination for each server, right click on the xml and select publish..

Visual Basic using SQL Database

So this is a homework question but I'm probably missing something really simple. I am working on a project where I was given a database. I'm not in the programming part of the assignment but I have to write the test case scenerios for the project before starting the project. Because I am working with an SQL Database that was provided. I am supposed to write the expected output from the database. If the user chooses shampoo from the products menu then the different brands of shampoo should then populate in my datagrid.
Because they gave us a sample database. How do I view it? I am I supposed to be able to write the expected output if I don't know what has been pre-programmed into the database?
Thanks in advance. I have already designed my layout and I guess I'm just stuck because I have been taught to plan your output before you program that way you know the program is working correctly. I don't want to write the assignment to find my output in case I did it wrong I guess, if that makes sense.
Here is how to do it in Visual Studio 2010
To create a data connection to the Northwind database—SQL Server
database file (.mdf)
On the View menu, click Server Explorer/Database Explorer.
In Server Explorer/Database Explorer, right-click Data Connections and
click Add Connection.
After you click Add Connection, either the Add Connection dialog box
or the Choose Data Source dialog box will appear.
If the Choose Data Source dialog box appears, select Microsoft SQL
Server Database File, and then click OK.
If the Add Connection dialog box appears, verify that the Data source
is set to Microsoft SQL Server Database File (SqlClient). If it is not
set to Microsoft SQL Server Database File (SqlClient), click Change to
open the Change Data Source dialog box, click Microsoft SQL Server
Database File, and then click OK.
Click Browse to locate the .mdf file that contains the Northwind
database.
Depending on the requirements of your version of the Northwind
database, either click Use Windows Authentication or click SQL Server
Authentication and type a user name and password to log on to the
computer running SQL Server. For more information, see Add/Modify
Connection (Microsoft SQL Server Database File).
Click OK.
A data connection to the Northwind database is added to Server
Explorer/Database Explorer.
Okay, so this should be pretty straight forward then:
Download and install SQL Management Studio Express.
Attach the database.
I wouldn't normally just list links in an answer, but this one really calls for it. These are very foundational URL's and won't be moving.

Attaching and detaching databases in Management Studio does not result in unloading old database and loading the new one

I have two versions of the same database, say DB1 and DB2. DB1 is a copy made of the mdb and the log file a month ago. The database structure and data has changed since then. I need to switch back and forth between these two copies in SQL Server Management Studio.
The structure of the Customer table in these versions is different. So it is easy to see which version is loaded in Management Studio.
I detach DB1 and attach DB2 and do select * on Customer and see the structure still belonging to DB1. How do I switch to DB2 properly?
I am using the right use DB statement and have the right db selcted in the dropdown on the left hand side for selecting databases.
The drop-down at the top controls which DB you are using, if the DBs are on the same instance of SQL Server. If they are different instances, use the "change connection" button at the top left, then pick your DB from the drop-down.
Somehow Management studio was caching the location of the file. When attaching the database, I had to go to the "current file path", and edit the wrong path and point to the right one. This had to be done even when after clicking the add button I had already chosen the right mdb file with the right path.

Visual Studio Database Project and SQL Server Management

I enjoy using SQL Server Management Studio for change and updating my database. Its easier, faster, and safer than writing changes myself.
I was looking into using some sort of version control for databases and read about using a SQL Server Database Project in Visual Studio 2010.
I scripted out an existing database and imported it into a new SQL Server Database Project. Now, from what I can tell, there is no GUI to edit the database; I can't add columns, change datatypes, or edit existing data without scripting it myself. For instance, in SQL Server Management Studio I can right click on a table-name and select "Design" and then add/edit columns, change datatypes, etc from there.
While Visual Studio's Database Projects has some features SQL Management Studio does not have I don't think I can live without a "table designer".
Is there a table designer built into VS's Database Project I'm just not seeing?
No, there's no table designer.
If you're starting to think about version controlling your database, you ought also to be thinking about writing actual SQL to implement your database objects. That's the route that the Database Projects force you down. If you can't write the SQL for your database changes, how are you going to be able to review and appreciate a diff between how a table was 6 months ago, and how it currently is in your project?
I've been using VS2008 Database Projects for about 10 months now for our version control. Every now and then I do still use the table designer, it is a quick and easy tool. I believe the majority of your question centers around workflow as this is what I found to be the most challenging part about development in a version controlled environment. I would recommend continuing to design your objects in Management Studio or however you're comfortable and then do a create script and import that script into your Database project. There are some quirks when doing this, you'll need to always script the create statement even if you're performing an alter in your environment. As well you'll need to remove any USE statements for your database as the context in which you're importing your scripts will always be in the project you're importing to.
We have found that a successful workflow for us to facilitate code deployment is to have a production branch which is branched to a Main (development branch) and then to test. All new development is done in Main and merged by changeset to each other environment as required.
You can import your scripts from your development environment by right clicking in the solution and clicking import scripts. I recommend that you check all the options to overwrite objects that exist, import extended properties and import permissions.
After changing your DB schema using SSMS's GUI tool, you can use Database project's Schema Compare tool to update your project files (set the source to be your database and target to be your project). This way you can keep using GUI tool to manage the schema and the database project will manage the versioning.
There is no visual table designer in Visual Studio 2010 Database Project. But, concerning version control for databases, there is a workaround - you can use SQL Server Management Studio together with Red Gate's SQL Source Control. It costs some money but definitely is worth it.