I have this program in java
to connect to a SQL Server
server = "ZF-SQL-MTRAZDB.NIS.LOCAL"
dbName = "MRAZ"
nameBaseDatos = "CD_LO"
table = "dbo.CD_LO_DATA"
user = "user"
password = "Pass"
url = "jdbc:sqlserver//"+ server + "\\" + dbName + "jdatabaseName=" + nameBaseDatos
driver = "com.microsoft.sqlserver.jdbc_SQLServerDriver"
Now I have to do the same with Visual C# 2010
in Windows XP
How can I do this program?? Because in java use JDBC
, Should I also use JDBC
?
Thanks for all!
The ConnectionString is similar to an OLE DB
connection string, but is not identical. Unlike OLE DB or ADO, the connection string that is returned is the same as the user-set ConnectionString
, minus security information if the Persist Security Info value is set to false (default). The .NET Framework Data Provider for SQL Server
does not persist or return the password in a connection string unless you set Persist Security Info to true.
You can use the ConnectionString
property to connect to a database. The following example illustrates a typical connection string.
"Persist Security Info=False;Integrated Security=true;Initial Catalog=Northwind;server=(local)"
Use the new SqlConnectionStringBuilder to construct valid connection strings at run time.
private static void OpenSqlConnection()
{
string connectionString = GetConnectionString();
using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = connectionString;
connection.Open();
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionString: {0}",
connection.ConnectionString);
}
}
static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
return "Data Source=MSSQL1;Initial Catalog=AdventureWorks;"
+ "Integrated Security=true;";
}
Data Source
or Server or
Addressor
Addror
Network Address
: The name or network address of the instance of SQL Server to which
to connect. The port number can be specified after the server name :
server=tcp:servername, portnumber`Initial Catalog
or Database
: The name of the database. The database name can be 128 characters or less.Integrated Security
or Trusted_Connection
: When false
, User ID
and Password
are specified in the connection. When true, the current Windows account credentials are used for authentication. Recognized values are true, false
, yes, no, and sspi
(strongly recommended), which is equivalent to true
. If User ID
and Password
are specified and Integrated Security is set to true, the User ID
and Password
will be ignored and Integrated Security
will be used.and other items
I hope this help you :) .