Issues with Visual Studio and devOps

  • Hi all

     

    Warning - long post alert.....

     

    We're just getting into DevOps and want to use Visual Studio for database development (branching, merging, etc).

     

    In Azure, I do the following:-

    1. New Project
    2. Name project (DummyDatabase).  Not sure if it makes a difference, but it's set to "Private"
    3. Click Repos (so I can initialise it)
    4. Under "Initialize main branch with a README or gitignore", I've unticked "Add a README" and chosen Visual Studio under "add a .gitignore"
    5. Click "Initialise"

    The repo only has a ".gitignore" file in it.

     

    In Visual Studio (2022), these are the steps I've taken:-

    1. Create a new database project
    2. From the "SQL Server Object Explorer" menu, choose my database (DummyDatabase) and set that as the source for "Schema Compare"
    3. Set my new project as the target
    4. Click Compare followed by Update to get the project up to date with the latest tables, stored procedures, etc

     

     

    The issue arises when I try to connect my VS project to my Azure repo.

     

    To attach the project to Azure, I do the following:-

    1. In the Git menu, select "Create Git Repository"
    2. Select "Existing Remote" from the options on the left
    3. Copy the URL from my Azure repo and paste it into the "Remote URL" box (format is "https://dev.azure.com/Organisation/_git/DummyDatabase")
    4. Click "Create and Push"

    I can see VS stage the changes and then I get the following error:-

    "rejected Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes before pushing again."

     

    I can't figure out where I'm going wrong so any help would be greatly appreciated.

     

    Once I get this sorted out, I'll be moving on to branching/merging (and we need to attached the branch to a different database) but I'll get to that bit in the future.

     

    Regards

     

    Richard

  • can you add a screenshot of the window in visual studio where you select existing remote?

    It sounds like you need to do a sync/pull first.

  • Yep. Pull first, then add stuff. You can't sync the two independently. One has to drive the other, especially initially.

     

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Hi both

     

    Thanks for the responses.

     

    @winston - I've attached the screenshot as requested

     

    @both - I don't get the option to do a pull first (unless I'm doing something wrong).

    I'm following the guide here:-

    Getting started with Database Projects and Version Control (oliviervs.be)

     

    I'm happy with creating the Azure project/repo but just can't get the Push to work.

     

    Regards

     

    Richard

    • This reply was modified 1 year, 1 month ago by  richardmgreen1. Reason: Spelling
    Attachments:
    You must be logged in to view attached files.
  • Go to the folder for the repo with a command line and type "git status". What do you get?

    With VS, should be an option to just pull: https://learn.microsoft.com/en-us/visualstudio/version-control/git-fetch-pull-sync?view=vs-2022#pull

    If there isn't, my guess is you create files in the local folder and then are trying to merge that with the remote. You should create the repos first and link them, then create your project.

    This likely is easy to fix in the command line. In VS, not so much. When you do this, you want to create a repo in one place only. Don't add files in the Azure repo (git remote) and add them locally. I'd have created an empty Azure DevOp repo, then created the local one from VS and then added the remote and pushed there.

  • @steve-2 - When I do the initial bits to get the stored procedures, etc into VS, there is no git subfolder in the project folder.  It appears to be a holding folder for the solution/project.

    That doesn't appear until I try to do the initial commit/push (from the screenshot I posted).

    I've tried creating an empty DevOps repo but I always end up with either a README and/or a gitignore file depending on the options I choose (I think this is what's causing the issue).

    How do I create a completely empty repo?

    I've tried variations of options when I initialise the repo but I always end up with something in there.

     

    Regards

     

    Richard

    • This reply was modified 1 year, 1 month ago by  richardmgreen1. Reason: Spelling/typos
  • OK, so it seems you might not know the basics of Git. I would assume when you create a VS project, you can set make this a git repo. If not, create a new folder and from the command line "git init" will do that.

    Alternatively, you can create a repo in Azure DevOps and then git clone the URL. For example in AzDO, I can create a new project:

    2023-08-08 11_09_47-Projects - Home

    When I look at this in Repos, I see this> I'd assume you see this. Note, I didn't click "initialize" at the bottom.

    2023-08-08 11_10_40-Files - Repos

    Once I have this, I can clone this in VS with the drop down.

    2023-08-08 11_11_02-Files - Repos

    I can also grab that URL (copy next to the top edit box) and type "git clone <url>" with the URL in that spot. That will clone to a subfolder below where the current command line is.

    If I've create a repo with my VS project, I'd use the second section to do the git remote add origin from the VS folder and then push changes.

  • Thanks Steve - that worked (I was initialising the repo when I didn't need to)

    Another (hopefully easy) question, is it possible to have the branch point the database to a different connection automatically?

     

    For example:-

    My main database is "DummyDatabase"

    My development database is "cl_DummyDatabase"

    When I create the branch, can I get the connection to change from "DummyDatabase" to "cl_DummyDatabase" without me going into the properties and updating the connection string?

     

    Thanks

     

    Richard

  • You might be able to do this programmatically through GitHub actions or workflows. I haven't done this, so I'm a little unsure what would be best.

    Generally, even when branching databases, I keep the database names the same because of the issues you can run into along these lines. If you want to work on a branch, rebuild the db to that branch.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks Grant - I'll have a look at those.

    We currently use SQL Clone to create our development databases so was just wondering if I could get the branch to point to the clone automagically somehow.

    I'll keep digging.

     

    Regards

     

    Richard

  • Grant, the original posted is using Azure DevOps, not GitHub. So, GH Actions is out. The OP would have to use Azure Pipelines instead. (Essentially the same thing as GH Actions.)

    Kindest Regards, Rod Connect with me on LinkedIn.

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply