Visual Basic using SQL Database - sql

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.

Related

Change Dataset access database Visual Studio

I've created a windows application with connected to an access database. Now I am re-using my code and project for a new application, and need to change the database for the new Access database, different columns and all.
Is there any way of replacing it on my project? I changed it in properties but can't see the dataset in my Forms to change at all. Will I need to go 1 by 1?
Right click on data connections in the server explorer, select add connection. Your installation may default to Sql Server, click the Change button to the right of Microsoft SQL Server (SqlClient) and select Microsoft Access Database File (OLE DB).

VS LoadTest does not save results into the SQL Server

I am performing a Load Test using VS, but the results are not saved in SQL Server.
When I run the test, the table LoadTestRun is populated with data, but when the test is done, the table LoadTestTestSummaryData stays empty.
Let me know if you need more information.
Thank you
As pre-steps you need for Performance and Load Testing with Visual Studio:
install and configure Visual Studio ULTIMATE.
SQL Server (e.g SQLEXPRESS 2012) (both SERVER & MANAGER) e.g.
Be sure that SQLEXPRESS service is running. You can run SQL Server Configuration Manager and start it manually. Be careful for the correct INSTANCE_NAME. Also in Task Manager > Services. Next go to Start menu and find VS2012 Cross Tools Command Prompt. Type the following:
cd C:\ Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE
and
SQLCMD /S localhost\sqlexpress /i loadtestresultsrepository.sql
This will create Load test DB schema that is required for VS 2012 Load tests.
On the Load Test toolbar, choose Manage Test Controllers. The Manage Test Controllers dialog box is displayed.
In the Load Test Results Connection String, click the browse button (…) to display the Connection Properties dialog box.
Note
If you change the connection string for a controller, then you must select the controller.
In Server Name, type localhost\sqlexpress or the name of the server that you used in step 2 such as ContosoServer1.
Under Log on to the server, choose Use Windows Authentication.
Under Connect to a database, choose Select or enter a database name. Select LoadTest from the drop-down list box.
Choose OK.
All these steps has to be executed in order to get the proper level of integration between VS, SQL ( and maybe Excel for reporting). I suspect that
table LoadTestTestSummaryData stays empty.
because you are missing one of the above mentioned steps.
Could you get to database where you saved your result in, should be something in \sqlexpress in default? if only one table, there could be something wrong with Visual Studio. If you didn't get any table from load test, I would suggest you reset your follow this MSDN link and see what you may have missed:http://msdn.microsoft.com/en-us/library/ms318550.aspx

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..

Migrate Fox Pro DBF files to SQL Server 2012 x64

I have among 80 and 100 Fox Pro DBF database files that I want to migrate to MSSQL Server 2012 x64.
Because are too much DBF data bases I'm looking for an automatic/non Manual way of move all data contained in these DBF files to MSSQL Server Data base Tables. One separate table for each DBF File.
I have tried the following code:
SELECT *
FROM OPENROWSET('MSDASQL', 'Driver=Microsoft Visual FoxPro Driver;
SourceDB=F:\SomeDBFPath;
SourceType=DBF',
'SELECT * FROM someDBFFile')
in order to see/explore the data of one DBF, but the following error messages appears:
OLE DB provider "MSDASQL" for linked server "(null)" returns an error.
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)"
I'm not interesed in use external software like a DBF converter or similar tools.
At this time I have installed the AccessDatabaseEngine_X64 file located at http://www.microsoft.com/en-us/download/details.aspx?id=13255 due to previous recommedations with no success.
Thanks in advance.
Do you have access to Visual FoxPro? If so, you can via the default menu of Tools -> Wizards -> Upsizing.
First, go into Control Panel, Administrative Tools. Under that is ODBC Data Sources (should be a 32-bit version). Go into that and then go to the tab for "System DSN" and click Add button to the right. You will then be prompted to "name" the connection. For grins, something like "UpsizeMyData". It will then prompt you through the connection information to the database you are trying to connect to, user / password for connection, etc. Go through and create the ODBC connection info and make sure the "Test Connection" at the end is successful.
Once this is done, get into VFP. From the menu steps above, it will bring up a dialog window for transferring a database. It will prompt you for the database you want to upsize... pick via a "Get File" dialog. After that, it will prompt you with connection information, the ODBC connection you just created above should be listed. Select that, then "Next". It will then prompt you for the SQL password to start the connection.
Once connected, it will look though your database and look at the tables. You will have a side-by-side picker dialog of all available tables and you can pick those you want to upsize... you can do one, many or all, then click "Next".
The next dialog will show you each of the tables you've chosen and allow you to confirm the data type from the VFP table to the corresponding column data type when pushed up to SQL. You can try by letting the defaults go and try. Click "Next".
Finally it will ask you which database you want to upsize to. You can pick an existing database, OR Add a new (may be your choice for first time to see how things go).

extract raw SQL query from a Crystal Report .rpt file

I've got an .rpt file that I did not write and can find no documentation about. I want to be able to review the SQL that is generated from this report so that I can figure out, well, what data it was pulling and what WHERE clause parameters were used.
I can open it up and see the report layout. But when I select Database|Show SQL Query... the report tries to connect to the data source. The problem is, the data source being used is unknown to me, probably an ODBC connection used by whoever wrote the query. All I can do at that stage is 'Cancel' and I'm back to looking at the report designer.
Am I missing something? Can I get to the SQL query without connecting to the datasource? It seems like viewing the selection criteria shouldn't be dependent on a data connection.
Thanks.
version: Crystal Reports 2008
I know that this is an old thread, but I encountered this same problem. Effectively we used to have a database/application that has since been aquired by an external agency.
Although they now have the database/application they don't have access to crystal reports, so we can't just send them the old report that we used to run. Likewise we can't run it as we don't even have the database set up anywhere.... So instead our plan was just to extract the SQL code generated by the report and forward that on.
We experienced the same problem, but the solution is actually pretty simple.
If you don't have access to the original data source, just create a new 'blank' datasource (such as an ODBC connection). As long as the connection to the datasource works (i.e. it is some kind of valid datasource this it works fine). When running the 'Show SQL' option point the report to this datasource. As long as you don't try to actually run the report (and only show the SQL) the operation wont fail. This worked for our situation anyway. (Crystal Reports 2008)
(I can give more details if it helps in any way.)
It should be possible to find out some details about the existing datasource, by selecting Database > Set Datasource Location... .
As well as enabling you to change the datasource location, this should show you some information about the current datasource, such as which type of datasource is being used, and possibly (dependant on the type of driver) the name of the database. It is likely to be less helpful if (as you surmise) the datasource is ODBC, but if it uses a native driver there may be something useful.
Without the password, I'm not sure how much you can do. It seems "Show SQL Query" requires to report to run first, then generate the SQL plan.
It's not ideal, but you could go to Database > Visual Linking Expert to at least see the tables and how they are joined, and the go to the Record Selection Formula Editor and see what the custom WHERE statements are.
Viewing the SQL of a Command in a Crystal Report File
There are times you have just the report file, but not the associated database structure that the report uses.
This is common when dealing with example reports of functionality you wish to mimic.
This is a workaround ONLY to allow you to see the SQL of a Command that a Crystal Report is based on, when you don't have the underlying database connection that the report is based on.
In essence, the dialog box has to be satisfied before it will show the SQL, so we fool it with a legitimate Data Source, just not one that would work with the SQL that is actually in the SQL Command.
Why does a report use a command? Doesn't Crystal Reports have the ability to link tables?
When a Crystal Report is based on a record set that is too complex for the table linking functionality within Crystal Reports, the report can instead be based on a SQL Query, usually developed/tested in another editor tool and pasted into the command. This allows advanced SQL functions to be utilized.
If you don't already have a Data Source on your computer set up that you can connect to, you will need to build one first.
A simple Microsoft Access .mdb file saved in a simple location will suffice.
I placed mine with the path C:\A_test\test.mdb to make it easy to find.
If you don't have one, google for a sample mdb file and download it, saving it with a name and location you can remember. (You won't ever actually open this file, but just connect to it.)
Once you have the file saved, open the ODBC Administrator and create a New Data Source.
(you can get to the ODBC Administrator quickly from Start > type ODBC in the Search)
On the User DSN tab, click the Add button.
Scroll down the driver list to Microsoft Access Driver (*.mdb), select it and click the Finish button.
In the Data Source Name box, type a name (I used MyTest).
Click the Select Button and select the mdb file you saved from a previous step, click OK.
Click OK again. You will see your new Data Source listed by the name you gave it. Click OK.
You now have the data source you will need for the next steps.
Open the Crystal Report you want to see the SQL command for, and click on Database Expert button or Database>Database Expert Menu.
Under Selected Tables, right click on the Command and choose View Command
The Data Source Selection Box appears. Select the Data Source you created (or one you already use) and click the Finish button. The View Command box should open with the SQL in the left pane. Copy the SQL into your favorite text editor.
Whats happening is that the crystal reports needs a database to connect to regardless if its the original source DB or not.
Create a local database or use a database stored on a server, added it to your ODBC Datasources and use it when connecting. After a successful connection you should be able to view the SQL query without an error.