Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

username , password and other parameters in sqlserver connection string

I'm new to C# and .net and just worked with php and mysql.
to connect to sqlserver express (in visual studio 2010) with c# we should provide a connection string that has lots of formats i found on the web specially in connectionstrings.
for example in standard format :
"Data Source=myServerAddress;Initial Catalog=myDataBase;UserId=myUsername;Password=myPassword;"

what is username and password? where can i find them? are they "root" and "" like in php mysql or something else?

as mentioned , i have created a database named "db.sdf" in sqlserver express in visual studio 2012.

I'm really confused. please help.

like image 380
Aliweb Avatar asked Apr 03 '26 02:04

Aliweb


1 Answers

If your database extension is SDF,you are creating SQL Server CE (Compact Edition) database file. Use this connection string

Data Source=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\MyData.sdf;Persist Security Info=False;

OR

Data Source=MyData.sdf;Persist Security Info=False;

More on this link.

UPDATE 1

You need the System.Data.SqlServerCe namespace.

SqlCeConnection conn = new SqlCeConnection("Data Source=\\Mobile\\Northwind.sdf;");
conn.Open();
.
.
.
conn.Close();

From MSDN:
Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

like image 197
John Woo Avatar answered Apr 08 '26 06:04

John Woo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!