20

I am trying to connect to my Visual Studio Online account, via web api. Following the steps here for here:

http://blogs.msdn.com/b/buckh/archive/2013/01/07/how-to-connect-to-tf-service-without-a-prompt-for-liveid-credentials.aspx

NetworkCredential netCred = new NetworkCredential(
    "myaccount@gmail.com",
    "mypassword");
BasicAuthCredential basicCred = new BasicAuthCredential(netCred);
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred);
tfsCred.AllowInteractive = false;

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
    new Uri("https://myaccount.visualstudio.com/DefaultCollection"),
    tfsCred);

tpc.EnsureAuthenticated();
Console.WriteLine(tpc.InstanceId);

However I get the following error message:

TF30063: You are not authorized to access .visualstudio.com

Ed Blankenship
  • 5,235
  • 1
  • 31
  • 31
Rajat banerjee
  • 1,781
  • 3
  • 17
  • 35
  • Please, do not include information about a language used in a question title unless it wouldn't make sense without it. Tags serve this purpose. – Ondrej Janacek Mar 05 '14 at 12:05
  • I assume `.tfsCredAllowInteractive = false;` was `tfsCred.AllowInteractive = false;` and `.tpcEnsureAuthenticated();` was `tpc.EnsureAuthenticated();` in your original code? – AeroX Mar 05 '14 at 12:13
  • Your code does not compile at the moment, can you edit it properly? – matthijsb Mar 05 '14 at 12:18
  • :) yes AeroX. @GrooV this is a sample console app which i wrote to test my tfs connection – Rajat banerjee Mar 05 '14 at 12:38
  • I was getting this error for a build - this method of authentication was a way of fixing it for me -> https://stackoverflow.com/a/45956538/852806 – JsAndDotNet Aug 31 '17 at 15:37

7 Answers7

31

After trying every coding option in the book, I turned to an alternative approach:

Logged out of Visual Studio Online from:

  • Browser(s)
  • Browser within Visual Studio IDE
  • Cleared my cache from C:\Users\ [your username] \AppData\Local\Microsoft\Team Foundation\5.0\Cache

and it worked...:)

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
Rajat banerjee
  • 1,781
  • 3
  • 17
  • 35
  • 3
    I realize this question was about VS Online, but I'm using VS 2015 and got the error in question. I did not have to log out. I closed Visual Studio 2015, cleared the cache, and opened the project in Visual Studio again. – jaycer Jul 07 '16 at 22:13
  • I have this error. I am supposed to access a team project in visual studio with work account login. After signing into visual studio with my personal account which wasn't part of the team project, I can't log into my work account in Visual Studio to access the team project. – naz786 Mar 15 '17 at 16:15
  • 1
    Instead of clearing it all, this might work too. C:\Users\[username]\AppData\Local\Microsoft\Team Foundation\7.0\Cache Open ServerMap.xml Locate duplicate entries. Remove the duplicate ones (likely to be old ones) Open LocationServerMap.xml do the same, leave the guid that exists in servermap.xml – Egbert Nierop Mar 23 '18 at 11:26
  • Logout from browser within Visual Studio IDE did the trick for me. – Grimace of Despair Mar 25 '19 at 10:20
11

We had this same error in Visual Studio itself after the switch to Azure DevOps (It couldn't connect to dev.azure.com). This is what I did to solve our issue.

  1. Go to Team Explorer
  2. Click the green plug button
  3. Click Manage Connections > Connect to a project
  4. Select one of the team projects you were already connected to
  5. Click Connect
James Esh
  • 2,219
  • 1
  • 24
  • 41
  • 1
    I had this exact same issue today after the move to Azure DevOps and this was the only way to fix the issue for me. It might have something to do with when I went to the Organization settings and enabled the new Azure DevOps Organization URL (https://dev.azure.com/). – ProgrammerAl Sep 15 '18 at 19:11
8

I have the same issue when I use git-tfs (which is also using TFS SDK to connect) for the first time with Visual Studio Online account on a brand new machine. I have tried to clear my browser caches, but it doesn't work for me. I don't think I have any cache for Team Foundation yet because the machine has never connected to any TFS before.

After some struggling, I found some simpler way to get everything working. Please just use this as the last resort because it may have side effects as comments below.

  1. Just run the Developer Command Prompt for VS2013 under Visual Studio Tools in your VS2013 folder.

  2. Run "devenv /resetuserdata" to clear your logon for Visual Studio 2013. Let it finish, it may take a while, on my machine it is around one minute.

  3. Then connecting to the Visual Studio Online account again, using your own tool or VS or "Open in Visual Studio" link from your Visual Studio Online home page. You will be prompted with the sign-in page now. Type in your correct username and password, you will get through to where you want to be.

It worked for me on at least two of my machines with this issue.

bigbearzhu
  • 2,381
  • 6
  • 29
  • 44
  • almost wasted a day on this, knew the problem but nothing was working before this command – afr0 Oct 17 '16 at 22:11
  • 2
    FYI, "devenv /resetuserdata" can be sort of a big hammer. It uninstalled all my add-ins and extensions. Had a ton of errors when launching VS again. – Casey Plummer Nov 30 '16 at 21:34
  • @Casey wish I read your comment before trying it. Would not recommend doing this to anyone. Downvoting because I don't think it's a good solution except as a complete last resort, and the other solution seems to solve the problem just fine. – Robert Noack Feb 10 '17 at 15:29
  • Thanks @Casey, have updated the answer to reflect the side effects it may have. Was trying this solution when my VS was relatively clean. – bigbearzhu Feb 13 '17 at 00:42
3

I had the same issue. What solved my problem was disconnecting (Team -> Disconnect from Team Foundation Server) from TFS and reconnecting (Team -> Manage Connections). Choose the appropriate TFS server when reconnecting. HTH!

DiligentKarma
  • 5,198
  • 1
  • 30
  • 33
1

You forgot to invoke the Authenticate method

Add tpc.Authenticate(); to your code after TfsTeamProjectCollection tpc = new TfsTeamProjectCollection( new Uri("https://myaccount.visualstudio.com/DefaultCollection"), tfsCred);

matthijsb
  • 909
  • 5
  • 12
  • Actually, i didnot but somehow while editing my post the synatx went crazy. I am using tpc.EnsureAuthenticated() – Rajat banerjee Mar 05 '14 at 12:41
  • EnsureAuthenticate uses your network credentials (for when you have your TFS server on your own network domain). Normal Authenticate uses the supplied basis credentials – matthijsb Mar 05 '14 at 12:52
0

I just ran into this same issue myself. I tried logging out of all my browsers, but nothing worked.

What did work was closing VS and then opening it by itself - NOT by opening a .sln file. And then going to the Source Control Explorer and opening my solution from there. For some reason I was only getting this error when I launched Visual Studio by opening the solution file.

matthew_360
  • 5,901
  • 9
  • 32
  • 40
0

It might be a big hammer but after several hours of struggling with a TF30036 error today I can confirm this was the only option that worked.

The cause for the error I know, our company set up CyberArk so now my password changes on a weekly basis but despite renaming several %AppData% directories (suggested elsewhere) and wiping all references in Credential Manager to the old entry it was still caching the information somewhere. This solved it and did not really seem to have too many side effects for me. Your mileage may vary.