Can't attach to SQL Server to debug SQLCLR Stored Procedure - c#

I want to debug a SQLCLR stored procedure in SQL Server. I have been trying to debug an SP in VS2015 Community and in the recently installed VS2017 Community editions without success. I am pretty sure that the problem lies in attaching to SQL Server but as I've done everything I can find mentioned online but to no avail.
When creating the database project in SQL Server Express LocalDB everything works fine. If I change the connection string to use my Developer Edition SQL Server, I then get an error. I have done the following:
I created a new database. I am the only user of the server and it resides on the same desktop machine that I am using for Visual Studio.
In Visual Studio I created a simple database project with a simple method to send some text to the output pipe.
[Microsoft.SqlServer.Server.SqlProcedure]
public static void mytest ()
{
SqlContext.Pipe.Send("in clr Craig1");
}
I edited the Target Connection String in the project properties to connect to the new database and successfully got a connection when pressing the connection button. The connection string used Windows Authentication for me, with the same user as the database owner.
I built and deployed the solution and checked the SQL Object Explorer to ensure that the SP was deployed. It was.
I selected the server and, using the right click, selected the "Allow SQL/CLR Debugging". I checked it again to ensure it was actually set.
I selected the stored procedure and with the right click, selected "Debug Procedure..."
The debug script was displayed. I stepped to the line to exec the SP and then pressed F11 to step in. At this point I was shown the following:
I pressed the attach and was shown the following error:
Thereafter, the procedure executes and performs the pipe function, but it does not let me do the attachment and the debugging.
Any ideas of what I'm doing wrong?
Thanks
Craig

You might just need to start Visual Studio with "Run as Administrator". I do not believe that I needed to do that when running Windows 8, but I am running Windows 10 now and definitely need to "Run as Administrator". I am guessing that you cannot otherwise attach to someone else's process (I have my Developer Edition running with a service account of "SQL Server", yet LocalDB always runs as the Login that started it, typically yourself). I have not tested to see if running Developer Edition as myself would still require "Run as Administrator", or how running Developer Edition as "Local System" would affect this behavior.

Related

Visual Studio 2017 tries to connect to Local Mysql with an IP when debugging

For some reason After a windows 10 upgrade resulting to a bsod event, I had to do a fresh install of my PC. I have visual studio 2017 and MySQL set up for my C# ASP.NET EF projects. I have installed MySQL similar to my old system and I have a laptop with similar setup which works okay.
The problem is when I try to debug the application tries to connect to the local mysql(version 5.7.23) using an IP instead of localhost and fails to authenticate.
MySql.Data.MySqlClient.MySqlException HResult= 0x80004005
Message=Authentication to host '' for user '' using method
`'mysql_native_password' failed with message: Access denied for user ''#'xxx.xxx.x.x'
(using password: NO) Source=MySql.Data'`
When I run update-database etc in the console of visual studio it connects to database alright and update tables etc. But it fails to connect when I debug the application.
I have maintained using localhost as string and changed to the IP still cannot connect on debug.
On the menu bar, choose View, Other Windows, Data Sources (or choose the Shift+Alt+D keys).
In the Choose Data Source window select MySql Database and press Continue.
in the Add Connection window, set server name: 127.0.0.1 or localhost.
Then test again using the debug to ensure it's now fixed.

Connections to SQL Server broken after Windows updates

I have Visual Studio 2013 C# solution that worked fine until some automatic Windows updates were pushed out to my PC. After these updates I am get an error on the connection.open command (server does not exist or access denied error message).
I created a new solution only for connection test purposes and from the newly created solution the connection to the same server is successful.
I uninstalled the Windows updates and my connections still don't work.
Any suggestion would be greatly appreciated.
Thank you
open run type services.msc press enter
it will show you list of services then go down and find SQL Server(MSQLSERVER)
and right click on it and press start.
hope this helps you

C# with MSSQL database Project Not running in another computers

I have Developed a C# project using Visual Studio 2015 and in this project, I have used the Microsoft SQL Server 2017 Database System.
The Problem is When I tried to run my project's Setup in other computer it shows the following Message whenever I run the project after the installation in another computer.
I have tried installing the MS SQL server in other computer it is displaying the same message. What I have done wrong?? Please help me. How to run my project in any computer?
You are not connected to SQL server yet. Make sure that the SQL services are running correctly. You can check them by clicking on My Computer->Manage->Services And Applications->Services.

How to enable the Create Unit Tests… popup in sql server object explorer Visual Studio 2013?

I having a problem with unit test for sql in visual studio ultimate 2013. I created SQL Server Database Project to unitest and connect the specific Server (like 10.11.31.1) with 'sa' database. Then I get all Stored, Table, Function... of it. But when I right click in a stored produred in Solution Explorer. there is not had the "Create Unit Tests..." popup. The same for SQL Server Object Explorer (it is disabled). How can I test in this case?
Please help me.
Thanks a lot.
SQL Server Object Explorer is the place to do this, and if it is disabled, then that indicates that there is an error somewhere in the script of the schema (maybe the stored procedure itself). When you correct the errors, it will no longer be disabled.
Some things you can try...
Try building the project to see if the compiler finds the error.
Follow the Walkthrough: Creating and Running a SQL Server Unit Test, found here: https://msdn.microsoft.com/en-us/library/jj851212(v=vs.103).aspx

programmatically restart sql server is win7

I have vs2010 click once winform program that performs the setup for another program. This setup program makes sure that they sql server is installed, creates the database/logins/tables, enables mixed mode, restarts the sql server(2008 express) then adds the stored procedures using the login and preloads some tables to get started. Works fine for winXP. When i do the setup on a Windows 7, it fails when it tries to restart the server.
I'm guessing it's a win 7 UAC 'feature' that prevents it, when I manually restart the server I get a UAC alert. I'm currently using the 'stopService' and 'startService' functions from http://www.csharp-examples.net/restart-windows-service/
Is there another way to do this in code without me having to install the SSMS to manually restart in Windows 7?
Have you tried running a prepared .bat file that restarts the sql instance via:
net stop mssqlserver
net start mssqlserver

Categories