Visual studio connecting to sql server managment

behzad gerami 1 Reputation point
2022-12-19T19:02:25.987+00:00

Hi,
My .net form and VS software work when I start it in visual studio debug and send data to SQL server management 2014 that I have table but if I use Extension in Vs and create windows installer project to make application for my code then it will stop connection to Microsoft Sql server mangment.
I have couple class that make connection to Sql.
this is my code in side class that make connetion to Sql server management.
then on main I have couple obj for each class.
String connectionString = "Data Source=" + DB_Path + "; Initial Catalog=Chillar;Integrated Security=True;TrustServerCertificate=True";
try
{
string sqlQuery = "INSERT INTO SCADA_"+Station+"_CH1 (SupplyTemp)value(@SupplyTemp)

            SqlConnection con = new SqlConnection(connectionString);  
            con.Open();  
            SqlCommand cmd = new SqlCommand(sqlQuery, con);  

How can fix this
I even change my SQL to TCP/IP but didnt work.
all connection is correct and when I run test connection it said connection is succesful but the application doesnt work.

Developer technologies Visual Studio Debugging
Developer technologies Visual Studio Setup
Developer technologies .NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. Bjoern Peters 8,921 Reputation points
    2022-12-19T23:24:25.547+00:00

    Hi @behzad gerami

    for me it sounds like your are using SQL LocalDB and not a real SQL Server... maybe LocalDB shuts down during Built-process

    And only to make sure... your app is not connecting to the Management Studio (you'd called it SQL Server Management 2014)... normally, Visual studio brings a version of LocalDB and that one only runs if VSStudio is started... (afaik)

    Maybe you try to install a SQL Server Express edition on your machine and migrate all structures/data to that db-engine... then it should also work with TCP and remotely.

    I hope my answer is helpful to you,

    Your
    Bjoern Peters

    If the reply was helpful, please upvote and/or accept it as an answer, as this helps others in the community with similar questions. Thanks!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.