Did you mean VB.NET?
.NET is a framework on which various languages are built on like: C#, VB.NET, F#, IronPython, etc.
Post the connection string you use in VB.NET as well as the connection string you use in C#.
mC = New SqlConnection("Initial Catalog = dbName; Data Source = Server; Integrated Security = SSPI;")
Cmd = mC.CreateCommand
Cmd.CommandText = "SELECT * FROM table"
mC.Open()
myReader = Cmd.ExecuteReader()
SqlConnection sqlCon = new SqlConnection(@"Data Source = Server;Initial Catalog= dbName;Integrated Security = True;");
SqlDataAdapter sqlda = new SqlDataAdapter("SELECT * FROM table", sqlCon);
DataTable dtbl = New DataTable();
sqlda.Fill(dtbl);
Foreach(DataRow row in dtbl.Rows)
{
Console.WriteLine(row["col1"]);
}
Console.ReadKey();
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
What is ce ? That is the exact connection string. I only changed the server address and database name. I don’t know why it works for VB.net but not C#.Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
What you posted is for ce. Not trusted as you climed to use.
The exact connection string you used for VB.NET should work for C#. You don't need to change anything because both VB.NET and C# both use the same SqlConnection class.
I implore you, please post the exact connection string you are using instead of the fake strings you keep showing us.
This is what you told us you needed to use :: Trusted Connection - SqlConnection - ConnectionStrings.com
But your connection string is for a CE device :: Trusted Connection from a CE device - SqlConnection - ConnectionStrings.com
I am confused for you, since you don't seem to know which one you need. Are you connecting to a CE device or an Instance server or SQL Express? Because it matters.
My
from MySQL
. If you don't want a password, then don't supply one.That is correct. The language makes no difference. If its not working, you've done something different in your C# code than it is in your VB.Net code.The exact connection string you used for VB.NET should work for C#. You don't need to change anything because both VB.NET and C# both use the same SqlConnection class.
Now there's a thought.I implore you, please post the exact connection string you are using instead of the fake strings you keep showing us.
The exact connection string you used for VB.NET should work for C#. You don't need to change anything because both VB.NET and C# both use the same SqlConnection class.
I implore you, please post the exact connection string you are using instead of the fake strings you keep showing us.
Hang on there till I find a genie in a bottle who can tell me what your tried...
You never showed us what you recently tried by placing both language codes side by side with the connection strings visible and unchanged as already requested.
The exact connection string you used for VB.NET should work for C#. You don't need to change anything because both VB.NET and C# both use the same SqlConnection class.
I implore you, please post the exact connection string you are using instead of the fake strings you keep showing us.
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class Form1
Private myC As SqlConnection
Private mCm As SqlCommand
Private myR As SqlDataReader
Private res As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
myC = New SqlConnection("Initial Catalog = DB; Data Source = serverName; Integrated Security = SSPI;")
mCm = myC.CreateCommand
mCm.CommandText = "SELECT * FROM table"
myC.Open()
myR = mCm.ExecuteReader()
End Sub
End Class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WFapp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String connectionstring = null;
SqlConnection cnn;
connectionstring = "Data Source = serverName; Initial Catalog = Database; Integrated Security = SSPI";
cnn = new SqlConnection(connectionstring);
cnn.Open();
}
}
}