მონაცემთა ბაზასთან კავშირი

sql connected
Standard Security (SQL Server Authentication)
მეთოდი1 :

Data Source=yourSQLServer; Initial Catalog=yourDB; User Id=yourUserName; Password=yourPwd;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Data Source=SQLDevelopment; Initial Catalog=SQL2008; User Id=sql2008; Password=######;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Users]", theSqlServer);

მეთოდი 2:

Server=yourServer;Database=yourDB;User ID=yourUserName;Password=yourPwd;Trusted_Connection=False;

SqlConnection მაგალითი:

SqlConnection theSqlServer = new SqlConnection("Server=SQLDevelopment;
Database=SQL2008; User ID=sql2008; Password=######; Trusted_Connection=False;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Accounts]", theSqlServer);

Trusted Connection (Windows Authentication)
მეთოდი 1 :

Data Source=yourSQLServer; Initial Catalog=yourDB; Integrated Security=SSPI;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Data Source=SQLDevelopment; Initial Catalog=SQL2008; Integrated Security=SSPI;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Emplpoyees]", theSqlServer);

მეთოდი 2 :

Server=yourSQLServer; Database=yourDB; Trusted_Connection=True;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection( "Server=SQLDevelopment; Database=SQL2008; Trusted_Connection=True");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Students]", theSqlServer);

Connecting to the Local SQL Server – Standard Security
მეთოდი 1 :

Data Source=(local); Initial Catalog=yourDB; User Id=yourUserName; Password=yourPwd;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Data Source=(local); Initial Catalog=SQL2008; User Id=sql2008; Password=######;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Companies]", theSqlServer);

მეთოდი 2 :

Server=(local); Database=yourDB; User ID=yourUserName; Password=yourPwd; Trusted_Connection=False;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Server=(local); Database=SQL2008; User ID=sql2008; Password=######;Trusted_Connection=False;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Clients]", theSqlServer);

მეთოდი 3 

Data Source=.; Initial Catalog=yourDB; User Id=yourUserName; Password=yourPwd;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Data Source=.; Initial Catalog=SQL2008 User Id=sql2008; Password=######;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Contacts]", theSqlServer);

მეთოდი 4 :

Server=.; Database=yourDB; User ID=yourUserName; Password=yourPwd; Trusted_Connection=False;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Server=.; Database=SQL2008; User ID=sql2008; Password=######;Trusted_Connection=False;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Stores]", theSqlServer);

Connecting to the Local SQL Server – Trusted Connection
მეთოდი 1 :

Data Source=(local); Initial Catalog=yourDB; Integrated Security=SSPI;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Data Source=(local); Initial Catalog=SQL2008; Integrated Security=SSPI;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Teams]", theSqlServer);

მეთოდი 2 :

Server=(local); Database=yourDB; Trusted_Connection=True;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection( "Server=(local); Database=SQL2008; Trusted_Connection=True");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Players]", theSqlServer);

მეთოდი 3 :

Data Source=.; Initial Catalog=yourDB; Integrated Security=SSPI;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Data Source=.; Initial Catalog=SQL2008; Integrated Security=SSPI;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Scores]", theSqlServer);

~
მეთოდი 4 :

Server=. Database=yourDB; Trusted_Connection=True;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection( "Server=.; Database=SQL2008; Trusted_Connection=True");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Grades]", theSqlServer);

Connecting to the Default Database of the User

If the Initial Catalog or Database parameter is not supplied, the database will default to the default database set for the user.
Data Source=yourSQLServer; User Id=yourUserName; Password=yourPwd;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Data Source=SQLDevelopment; User Id=sql2008; Password=######;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Regions]", theSqlServer);

Connecting Via an IP Address

Data Source=123.456.789.012,1433; Network Library=DBMSSOCN; Initial Catalog=yourDB;
User ID=yourUserName; Password=yourPwd;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection("Server=10.0.0.1,1433; Network Library=DBMSSOCN; Initial Catalog=SQL2008; User ID=sql2008; Password=######;");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Sales]", theSqlServer);

Connecting to a SQL Server Instance

Server=yourSQLServeryourInstanceName; Database=yourDB; Trusted_Connection=True;

SqlConnection მაგალითი :

SqlConnection theSqlServer = new SqlConnection( "Server=SQLDevelopmentSQL2008Instance; Database=SQL2008; Trusted_Connection=True");
SqlCommand theSqlCommand = new SqlCommand("SELECT * FROM [dbo].[Products]", theSqlServer);

Trusted Connection From a CE Device

Data Source=yourSQLServer; Initial Catalog=yourDB; Integrated Security=SSPI;
User ID=yourDomainyourUserName; Password=yourPwd

Enabling MARS (Multiple Active Result Sets)

Server=yourSQLServer; Database=yourDB; Trusted_Connection=True; MultipleActiveResultSets=true;

Connecting to a Local SQL Server Express Instance

Server=.SQLExpress; AttachDbFilename=yourMDFFile.mdf; Database=yourDB; Trusted_Connection=Yes;

Connecting to a Local SQL Server Express Instance (Database File in Data Directory)

Server=.SQLExpress; AttachDbFilename=|DataDirectory|yourMDFFile.mdf; Database=yourDB;
Trusted_Connection=Yes;

Facebook (0)