none
How to add server database to C# application? RRS feed

  • Question

  • I am trying to explain it as clearly as I can.

    This youtube video ( https://www.youtube.com/watch?v=hdNDfQXB90E ) is provided by another forum member, but I cannot follow it. I decide to start another new thread, because this topic is not really related to my original thread .

    Here is my case: Visual Studio is installed in local machine desktop, so I will need to develop C# application on local machine desktop, when the application is done, application will be moved to desktop virtualization, so everyone can use the application there. Server-based database is on desktop virtualization.

    So far, I have a question related to the above youtube video: At time 0:10, when I try to add Server-based database, error message(screenshot attached) pops up. Of course it could not locate the database from local desktop.

    So when I develop application on local desktop machine, how can I get Connection String for desktop virtualization database? I could not open sln file from desktop virtualization, since no software is installed there. It seems to me that I need to add the database when developing the application, but Visual Studio could not reach the desktop virtualization database.

    Thanks.






    • Edited by VA_er Tuesday, March 12, 2019 5:13 PM
    Tuesday, March 12, 2019 5:04 PM

Answers

  • Visual Studio, desktop virtualization and an enterprise-wide database aren't really connected. It ultimately doesn't matter where you run the app (virtualized or otherwise) so let's throw that conversation out. Provided it runs on a machine with network access to your enterprise-wide database it'll work (ignoring permissions/network issues). 

    Let's focus on developing the app in Visual Studio which is what this forum is for. On your development machine do you have access to the database you want the app to ultimately connect to? If not then you aren't going to get very far in the development of an app to use it. In this case you could create a local DB to develop against but if your actual database is large this is going to be tedious. This is exactly what the video was trying to do and probably isn't applicable to your case.

    If you do have access to the database from your local development machine that is running Visual Studio then you don't need a database project or anything. Use SQL Server Object Explorer (Views menu) to connect to the database running on the server. Get the connection string from its properties and then use that for your local development.

    Later when you move the application to the final localization where it'll run from (virtual desktop or whatever) then the most you should have to change is the connection string. In most cases it will remain the same but you might need to adjust it to use SQL authentication or Windows auth if that differs from what you were using when you were developing locally.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, March 12, 2019 7:58 PM
    Moderator

All replies

  • That video is pretty old and quite a bit has changed since then. That video is demoing if you needed to create a local DB for your app instead of using a server. So the first question is can you create and run your app against a SQL Server running on the network somewhere?

    If so then use SQL Server Object Explorer (Views menu) to find that SQL Server instance. As part of the properties it'll give you the connection string. Put that connection string into your config file instead of using the SQLExpress connection string that the video was using. You don't need to add a database project or .MDF to your solution.

    If you want to run a local DB instance for now then you need to decide where the DB schema is going to reside. If that schema already exists on a SQL Server database somewhere then either import the schema using SQL Database Project or have your DBA backup the DB and give you a snapshot. You can then hook up to that local DB file using LocalDB (we don't use SQLExpress anymore). 

    If there is no current DB but you want to one day have it hosted on a server AND you are creating the DB as part of this code then creating a SQL Database Project in your solution would be the way to go. You will then have a database project that holds the schema where you can set up tables, sprocs, etc. This project will be automatically hooked up to LocalDB when you debug it so you can use SQL Server Object Explorer to see the connection string. Like mentioned earlier, copy that connection string to your config file in lieu of the SQLExpress connection string that was given in the video. Note that to get the DB to show up under SSOE you need to deploy it at least once. I've had issues with this in the past so what I tell my students is to set the DB project as the startup project and then F5 to run the code. You should see (in the Output window) some messages about the DB being deployed. When that completes the DB is now in LocalDB and you can switch back to your regular startup project. You might need to repeat this step if you make schema changes later. Finally note that the "runtime" database you'll want to target is the LocalDB instance, not ProjectsV13 (or whatever number).


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, March 12, 2019 6:29 PM
    Moderator
  • NO, Not IT, not able to access SQL Server Management Studio, or whatever. Just an employee, has the permission to access the database (see the screenshot ODBC Data Source). Again, Visual Studio software is not on desktop virtualization.

    I am not IT, not sure how to describe. Basically, I am talking about accessing enterprise-wide database, but in order for an employee to access enterprise-wide database, the employee needs to be in desktop virtualization environment.

    Local machine: where Visual Studio is installed.

    Desktop virtualization (Citrix): Where to find ODBC Data Source information. No Visual Studio here, cannot develop application here.

    • Edited by VA_er Tuesday, March 12, 2019 6:49 PM
    Tuesday, March 12, 2019 6:34 PM
  • Visual Studio, desktop virtualization and an enterprise-wide database aren't really connected. It ultimately doesn't matter where you run the app (virtualized or otherwise) so let's throw that conversation out. Provided it runs on a machine with network access to your enterprise-wide database it'll work (ignoring permissions/network issues). 

    Let's focus on developing the app in Visual Studio which is what this forum is for. On your development machine do you have access to the database you want the app to ultimately connect to? If not then you aren't going to get very far in the development of an app to use it. In this case you could create a local DB to develop against but if your actual database is large this is going to be tedious. This is exactly what the video was trying to do and probably isn't applicable to your case.

    If you do have access to the database from your local development machine that is running Visual Studio then you don't need a database project or anything. Use SQL Server Object Explorer (Views menu) to connect to the database running on the server. Get the connection string from its properties and then use that for your local development.

    Later when you move the application to the final localization where it'll run from (virtual desktop or whatever) then the most you should have to change is the connection string. In most cases it will remain the same but you might need to adjust it to use SQL authentication or Windows auth if that differs from what you were using when you were developing locally.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, March 12, 2019 7:58 PM
    Moderator
  • CoolDadTx: Could you please move this thread back to C# forum?  It does not really fall under Excel forum, since the application is written in C#, it is more about C# programming. It is C# application which contains partial code interacting with Excel, it is not Visual Basic Application. I feel like some of my threads had been inaccurately moved to other forum. Secondly, I believe there are much fewer viewer on Excel forum.

    Therefore, I would appreciate if you could move my post back to C# forum.

    Thanks.

    Thursday, March 21, 2019 9:53 PM
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Jack

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 25, 2019 8:06 AM
    Moderator