fbpx
Welcome, Guest
Username: Password: Remember me
Share your code snippets, screen shots etc. here
  • Page:
  • 1
  • 2

TOPIC: Virtual Machines - X# and related VS & SQL stuff ...

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #1

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Hi X# guys,

I am currently working with a Virtual Machine which is running X# with all the related apps like Visual Studio, SQL Server and Management Studio.

I am making available some 'ClickStart' eNotes I mad a while back on VM's for a previous 'DevShare' event.

Here is the link to my OneDrive folder :-

1drv.ms/u/s!AiCBl-gBWjY9g_dRSaFZqZdBI1Aojg

At the moment I am just starting to add a further Appendix section to hold everything that I have done yesterday to get my VM working for X#. In the following image you can see the empty sub-folders (Appendix 'X#') :-



I will let you know when the new version of the CHM is available.

Hope this helps,

Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #2

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1406
  • Karma: 6
Hi Phil,

according to some Microsoft documentation about virtualization you need at least 2 cores for Windows versions after Windows 7. XP can run with one core, but Windows 7 needs at least two cores.

So this is not an issue of Visual Studio or SQL Server, but of the VM OS. X# (and XIDE) are not ressource hogs, so they may behave a bit better in underpowered environments (during my last flights to New York and back, I have programmed happily witn XIDE/X# on my Windows tablet with only 4 GB of memory, a Core i3 with 1,7 Ghz and a 11" 1366x768 screen).

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #3

This looks great. I will do also some "documentation" with Word. Also, I finished my OS Upgrade and Hyper V install and it looks like VS 2017 (incl. x#) and SQL Server 2016 are running. Finanly, imported your database and now I am ready to go...I am <--so--> am excited!!!

Cheers
Michael

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #4

Wolfgang.

I would love to say that this problem is the fault from Microsoft, but that is not the case.
We simply mad an error in our code which causes our background scanner to crash on machines with only oen (virtual) CPU.

Robert
XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #5

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1406
  • Karma: 6
Hi Robert,

thanks for this clarification!

We humans all make errors, and we programmers seem to make more than other people (at least is this the sensation I have during my daily work). But only serious programmers will admit when they make an error.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #6

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Wolfgang, Robert and all,

My findings from the experimentation I have carried out would appear to agree 100% with Robert's statement.

With 1 processor chosen for my VM the C# cade for small test apps compiled and worked, whereas the X# equivalent did not.

Changing the VM settings so that I used 2 processors, seemed to allow the X# code for these test apps to run equally as well as the C# cones.

At the moment I am not too bothered with the setting, as long as I can keep going with my work on integrating SQL use with X# apps in VS 2017 - for Michael and any other interested guys.

Well all should learn from our mistakes, and hopely other can too - hence the need for us all to be open and honest - thanks Robert !

Must shoot, taking daughter to railway station ;-0)

Regards,
Phil.
Wales, UK.

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #7

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Hi Michael,

I am glad to hear about your success, so far.

Now that you have imported the data file (MDF) I assume it is in 'C:\Temp' and that the file / folder is set to full edit facilities etc..

The next step on the way to getting X# up and running with SQL is to attach the chosen database to either Management Studio of the facilities in VS.

Right click the 'Databases' folder as seen below :-



Then navigate to one of the available MDFs - see below :-



Then click OK to get stuff going .. :-



If you have things set up correctly you will now see the new entry under 'Databases' :-



Enough for now, in my next post we will try and access the data by sending a query and listing some results.

Good luck any gut following Michael and his quest.

Cheers,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #8

Hi Phil,

successfully accomplished.

Cheers,
Michael

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #9

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Okay SQL guys,

A short post about Attached and Detached databases. This topic is 'small' but not an easy one - I have been fighting it for years, it would seem.

Lets start this 'art form' topic (no rhyme nor reason!?) by looking at the Management Studio end of things.

If we have a SQL server showing in the 'Object Explorer' pane, then before we can access a specific MDF (data base) we have to have it showing in the folder called 'Databases'. The way MDFs get into and out of the 'Databases' folder is by Attaching and Detaching. Sounds easy but some times things seem to get 'locked up' (from time to time) and we have to resort to closing apps and restarting them - messy. I have learned to live with this - but the good news is that from X# code life is not as 'strange' ;-0)

Previously, we saw in an image how we Attach by right clicking the 'Databases' folder, but to 'Detach' we need to right click the required Database entry itself. See below :-



If all goes well (to plan) then the entry will disappear from the Object Explorer list - but then you may also need to refresh this list, and it may behave slightly differently in your version of Management Studio or Visual Studio - I did say ... "an art form!".

So Tasks and Detach ... do the trick, hopefully, of removing the MDF from the list.

Now then, going further on this rather tricky topic, if we have an MDF attached in the Object Explorer pane in MS or VS we may get an issue in our X# coded application when we run it - but apparently only the first time we try.

Sometimes I need to Detach an MDF and this frees the .NET app to work okay, but more strangely the re-attached MDF seems then not to bother our code from running smoothly. As I said its a bit of an 'Art Form' and is one aspect I have struggled with since the start of my SQL experience many years ago. I have learned to live with it - BUT - I do need to tell, and warn, you of the possible problems. Just be aware of what I have reported and you will survive.

Sometimes I may even get an error message box which says I can't detach from the MS/VS shell, so then I need to close and reopen MS (and/or VS) and this seems to clear things so I can then do a clean 'Detach'.

From our .NET code we don't actually do Detach / Attach - we seem to just need to supply a connection string. Anything else may be hidden from us coders by the .NET ADO.NET system.

Finally, you could say why bother when we could do it more simply from .NET code. Well, the answer is that it is VERY useful to be able to use Management Studio to check-out our sample database. Look at the data, run some basic queries etc.. Here is a good and simple place to start :-



We are asking to have returned to us as a data set, all the customers from the Customer table. This simple query is supplied for us by the context menu option - here are the results :-



We will look at making some of our own queries in the next post - queries directly from the IDE in Management Studio (or VS).

See you in the next post,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #10

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Okay Michael and all,

Lets now go a step further and from MS or VS write and apply our own queries to the sample MDF we saw previously.

Without using a 'provided' context menu option we can open a new query pane of our own, and then type in our own query, then execute it against our chosen database.

So lets get a new query pane - see below :-



In the new window / pane I have manually type my own query - a variation of the one we saw the IDE provide previously - check this out :-



Notice in the above image that we need to select the 'Execute' button (or F5) to send the query to the database engine. The MS shell (or IDE) actually provides some intellisense for the script we type in. The SQL query script is called 'T-SQL' and said as "tee sequel". 'Tee' stands for 'Transact'

Lets see the results set we get returned :-



Check that the results are in order of 'City', A - Z.

Now then, we can actually create queries as complex as our simple data allows us to.

Here is a JOIN with filter and sorting :-



You can copy this for yourself, and then create and execute queries of your own. I would often do this before I went to the .NET code and queried from there.

Next stop for us is using the same database from the .NET code - in fact X# code. We will use Linq to SQL where we still operate on Tables. No 'Entities' for a while, we do that later.

Good Luck,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #11

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Hi again folks,

The next step in me helping new guys to get into SQL with X# will take me a little bit longer than usual. (A day or so.) This is because I will use the notes in the Appendix 'X' section of my "ClickStartLINQ" eNotes to make a small test app which will access the MDF we used previously with Management Studio. So I will be coding from scratch - just to show how it is done, and because my old C# and Vulcan demo apps are in a bit of confusion after 8 years of changes - so a clean start sounds a good idea.

Here is what I will be using to guide me :-



And here is where my copy of the MDF exists / resides :-



Wish me luck !

You can be trying out new queries for yourselves in Management Studio, or VS 2017.

Regards,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #12

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Good morning Pearls People (of the Forum variety),

I have made a good start to doing some X# code to allow us to access an existing SQL database.

The link below is to my OneDrive folder so that you can share and download the small app.

1drv.ms/f/s!AiCBl-gBWjY9g_dtNpfg1E3mcQr-NA

For those guys who are unfamiliar with SQL use and operation from coded .NET apps, getting a working connection string which finds both an Instance of a SQL server and the data file, is a VERY good first step to making a working app.

If you have followed my posts so far (like Michael) then this small app should work for you.

Good Luck!

Here are a couple of images to show you what you should get :-



And now the WPF form but without the data in the 'DataGrid' control - grey and at the bottom of form.



I will now add the extra (but still small) amounts of code to allow us to return and show the Customer table data.

Cheers,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #13

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Okay guys, we've done it !

We now have our foot firmly in the door (we are on our way, big time).

The attached image shows that we can now retrieve the data set for all customers in the Customer table - using only our own .NET code - of the X# syntax variety.

The WPF form has a DataGrid control which is bound to the returned query data set.

There is hardly any code and script to do this as you will see in my next post when I have eaten some food !

Here are the ten customers :-



Hope this interests a few guys - I will post a working solution later this afternoon.

And before that I will show and explain the code/script behind this simple one Table sample using 'Linq to SQL' technology.

Regards,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #14

Hi Phil,

SqlConnectionStringBuilder has properties for all the different connection string parameters,
so rather than doing oSCSB["Data Source"] := "xxxxx" which is of course susceptible to typos, you should be able to do oSCSB:DataSource := "xxxxx" which is a bit more reliable and should give you IntelliSense help.

HTH

Nick

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #15

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Hi Nick,

Good point ! This is a small problem coming from me using old, but working, code from way back and then the good old copy and paste ;-0)

I was focusing on getting guys into using real live SQL data ASAP, so that is my excuse.

Also for your knowledgeable ears, I do intend to get from L2S (Linq to SQL) to L2E (Linq to Entity) as soon as possible. It was just that L2S makes a nice simple in between stage for guys new to all this stuff.

Thanks for the input.
Cheers,
Phil.
Wales, UK.

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #16

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Nick,

I followed up your tip and got all but one property to translate.

I have attached an image of the new working static method - I can't find any alternative for 'Trusted_Connection' and I had to change the name for the 'ConnectTimeout' from "connection".

My example will run okay without a value being specified for 'Trusted_Connection'.

Any ideas or comments on this ? I have to admit it is not my strong point - most of what I have ever used for connecting was given to me by Willie Moore years ago. And it just worked.



Speak soon,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #17

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Here is the simplest of working X# solutions, accessing the SQL database to retrieve Customers.

Note that although the MDF has more than one Table, we currently are just accessing one, that of Customer.

1drv.ms/f/s!AiCBl-gBWjY9g_gFw1K7mcSot8SreA

I will now make changes to add classes for the other existing Tables in the MDF, and update the look / feel of the main WPF form to suit.

Hopefully by a click of a button we will be able to display different data sets returned from the SQL engine for different queries we make and send.

Attached below is the code for the Customer class :-



And now shown below is the calling code which uses pure LINQ code, not T-SQL script :-



Under the hood, L2S technology sends a T-SQL query for us - BUT - we don't need to know what is being done for us.

However, any knowledge of SQL and select statements is more than helpful to any modern .NET coder, so don't run away from learning ;-0)

Fingers crossed,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #18

Hi Phil,

I think that IntegratedSecurity is the same as Trusted_Connection ie. having set IntegratedSecurity the Trusted_Connection property is no longer required... but not 100% sure about that.

Nick

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #19

Hi Phil,

this was interesting. Finally, I was able to run the app. The concept is more or less clear but a lot of questions are popping up.

1. There is nothing like a "dbServer object" that takes care of all these SQL connection strings?
2. There is no "automated" class generation for all the SQL table fields? Means, hand-written code is the solution. In case of multiple large tables, we need to do this by ourselves?

In other words: a visual "SQL stuff builder", where I select the SQL Server, Table, fields and the "builder" creates the rest does not exist :-)

3. Syntax of X#: there are quite a few unknown commands to me. e.g what does "local implied" mean. Also, it looks like I can define variables somewhere in the code and not necessarily at the beginning. How can I look up the definition?

4. WPF is also absolutely new to me. Based on my research WPF is the way to go. Do I need to learn (besides X#, SQL) also XAML?

As of today, this seems to be an intersting journey. I think as a next step for me I need to digest the code and try to re-build it by myself. I am pretty sure I need to cheat and look at Phils code. Especially the SQL connection stuff looks complicated...

Have a great night.
Michael

Please Log in or Create an account to join the conversation.

Virtual Machines - X# and related VS & SQL stuff ... 1 year 10 months ago #20

  • Phil Hepburn
  • Phil Hepburn's Avatar Topic Author
  • Offline
  • Posts: 737
  • Karma: 7
Hi Michael,

I am really glad you managed to follow along, and I hope a few others may do so as well ;-0)

As for your questions, well many/most of them will just disappear when we take the next step to EF6 (entity framework) where we have similar code BUT deal in 'Entities', which is really .NET complex classes. We give up thinking in tables, and all the relational mapping is easily sorted out for us, once we define our entity classes. So all is done in .NET code, like what we are used to.

The only reason I used 'L2S' was because it proves a useful stepping stone to get to EF6, and it allows us to see how EF simplifies things on the SQL side of things.

I understand you need time to try out, and digest, the stuff we have seen so far. I did the same with Nick Friend's MVVM sample - three weeks I sat there I seem to recall ;-0) But I got there in the end.

As for WPF, we will use it in a 'simple and straight forward' way - still very powerful however.

When we use the EF6 approach we will first define the Entity classes, and then the code will create the database for us - its called 'Code First'. This is the approach I like to use - BUT - as you have seen, with L2S we can easily use existing data tables.

Using EF6 we will also see how to populate our database from entities, which automatically place data in the correct and most suitable Tables.

When we use EF6 we can effectively forget about SQL, all we MUST do is use LINQ to deal will all our collections of object items.

No doubt I will have some other useful points in the morning.

And remember, we have done all this with a "Virtual Machine", and with software which is FREE from Microsoft and also the X# Team - all it cost you was a few Euros, for a Windows upgrade and some time and effort to work with me ;-)

Hope you sleep well after the mental efforts and brain activity.

I have another (extended) sample to post, it will help you go further - more simple sample code to copy and adapt etc..

Here is an improved but not finished sample output :-



Cheers,
Phil.
Wales, UK.
Attachments:

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2