Thursday, April 9, 2020

Establishing connection to SQL Server on local machine, C#

The machine name is JOHN-PC
The SQL Server name is: TEW_SQLEXPRESS
The database name is myDB

using System;
using System.Data.SqlClient;

namespace CSharpConnectToSQLServer
    class Program
        static void Main(string[] args)
            Console.WriteLine("Hello World!");
            string connetionString = null;
            SqlConnection cnn;
            connetionString = @"Server = JOHN-PC\TEW_SQLEXPRESS; Database=myDB; Trusted_Connection=Yes;";
            cnn = new SqlConnection(connetionString);
                Console.WriteLine("Connection Open ! ");
            catch (Exception ex)
                Console.WriteLine("Can not open connection ! ");


Thanks to:
Using the @ symbol:
The general body of the code:

No comments:

Post a Comment

Solidworks macros eith ChatGPT

 Record a simple using thr Solidworks macro recorder, upload it to ChatGPT, and explain to ChatGPT how you want it changed:  https://youtu.b...