Home Database Mysql Tutorial C#连接SQL Server的常用字符串

C#连接SQL Server的常用字符串

Jun 07, 2016 pm 04:20 PM
server string Commonly used connect

一:C#连接SQL数据库 DataSource=myServerAddress;Initial Catalog=myDataBase;UserId=myUsername;Password=myPassword; DataSource=190.190.200.100,1433;Network Library=DBMSSOCN;InitialCatalog=myDataBase;User ID=myUsername;Password=myPassword; Ser

   一:C#连接SQL数据库

  DataSource=myServerAddress;Initial Catalog=myDataBase;UserId=myUsername;Password=myPassword;

  DataSource=190.190.200.100,1433;Network Library=DBMSSOCN;InitialCatalog=myDataBase;User ID=myUsername;Password=myPassword;

  Server=myServerAddress;Database=myDataBase;UserID=myUsername;Password=myPassword;

Trusted_Connection=False;

  Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

  Server=myServerNametheInstanceName;Database=myDataBase;Trusted_Connection=True;

  DataSource=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

  1:Integrated Security参数

  当设置Integrated Security为 True 的时候,连接语句前面的UserID, PW 是不起作用的,即采用windows身份验证模式。

  只有设置为 False 或省略该项的时候,才按照 UserID, PW 来连接。

  IntegratedSecurity 还可以设置为:sspi,相当于True,建议用这个代替True.

  DataSource=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

  DataSource=myServerAddress;Initial Catalog=myDataBase;Integrated Security=true;

  DataSource=myServerAddress;Initial Catalog=myDataBase;;UserID=myUsername;

Password=myPasswordIntegrated Security=false;

  2:参数Trusted_Connection

  Trusted_Connection=true,将使用当前的 Windows 帐户凭据进行身份验证

  Trusted_Connection=false;将不采用信任连接方式(也即不采用Windows验证方式),而改由SQL Server 2000验证方式

  Server=myServerAddress;Database=myDataBase;UserID=myUsername;

Password=myPassword;Trusted_Connection=false;

  Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

  3:Initial Catalog是你要连接的数据库的名字

  4:WINCE连接

  DataSource=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;UserID=myDomainmyUsername;Password=myPassword;

  二:可以利用SqlConnectionStringBuilder,这样不必去记住名称。

  SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder();

  scsb.DataSource =@"(local)SQLExpress";

  scsb.IntegratedSecurity = true;

  scsb.InitialCatalog = "Northwind";

  SqlConnectionmyConnection = new SqlConnection(scsb.ConnectionString);

  三:可以利用属性中的Setting来自动设置连接字符串

  1:在type中选择(connection string),

  2:在DataSouce中选择数据源,,然后再Server中输入服务器名,本地用(local)SQLExpress

  3:选择登陆验证方式,本次选Windows验证(即信任连接IntegratedSecurity=True)

  4:选择数据库名,确认即可

  DataSource=(local)SQLExpress;Initial Catalog=Northwind;Integrated Security=True

  server =.sqlexpress;integrated security = true;database = northwind

  最后附上一个我自己的测试用例:

  using System;

  using System.Collections.Generic;

  using System.Linq;

  using System.Text;

  using System.Threading.Tasks;

  using System.Data;

  using System.Data.SqlClient;

  namespace ConnectDB

  {

  class Program

  {

  static void Main(string[] args)

  {

  SqlConnection sqlCon = new SqlConnection();

  sqlCon.ConnectionString = "Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=SSPI";

  sqlCon.Open();

  SqlCommand sql_Command = new SqlCommand();

  sql_Command.CommandText = "Query Text";

  sql_Command.Connection = sqlCon;

  SqlDataAdapter dbAdapter = new SqlDataAdapter(sql_Command);

  DataSet dbSet = new DataSet();

  dbAdapter.Fill(dbSet);

  //dbSet.GetXml();

  Console.WriteLine(dbSet.GetXml()。ToString());

  sqlCon.Close();

  Console.Read();

  }

  }

  }

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to connect keep body fat scale How to connect keep body fat scale Mar 07, 2024 pm 04:50 PM

How to connect the keep body fat scale? Keep has a specially designed body fat scale, but most users do not know how to connect the keep body fat scale. Next is the graphic tutorial on the connection method of the keep body fat scale that the editor brings to users. , interested users come and take a look! How to connect the keep body fat scale 1. First open the keep software, go to the main page, click [My] in the lower right corner, and select [Smart Hardware]; 2. Then on the My Smart Devices page, click the [Add Device] button in the middle; 3 , then select the device you want to add interface, select [Smart Body Fat/Weight Scale]; 4. Then on the device model selection page, click the [keep body fat scale] option; 5. Finally, in the interface shown below, finally [Add Now] at the bottom

How to install, uninstall, and reset Windows server backup How to install, uninstall, and reset Windows server backup Mar 06, 2024 am 10:37 AM

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

How to connect OnePlus watch to Bluetooth headset_How to connect OnePlus watch to Bluetooth headset How to connect OnePlus watch to Bluetooth headset_How to connect OnePlus watch to Bluetooth headset Mar 23, 2024 pm 01:16 PM

1. Place the earphones in the earphone box and keep the lid open. Press and hold the button on the box to enter the pairing state of the earphones. 2. Turn on the watch music function and select Bluetooth headphones, or select Bluetooth headphones in the watch settings function. 3. Select the headset on the watch to pair successfully.

Detailed explanation of the method of converting int type to string in PHP Detailed explanation of the method of converting int type to string in PHP Mar 26, 2024 am 11:45 AM

Detailed explanation of the method of converting int type to string in PHP In PHP development, we often encounter the need to convert int type to string type. This conversion can be achieved in a variety of ways. This article will introduce several common methods in detail, with specific code examples to help readers better understand. 1. Use PHP’s built-in function strval(). PHP provides a built-in function strval() that can convert variables of different types into string types. When we need to convert int type to string type,

Steps to connect game controller to Gohan Arcade Steps to connect game controller to Gohan Arcade Mar 19, 2024 pm 03:55 PM

How to connect Bluetooth controller to Gohan Arcade? Gohan Game Center is a game box used by many mobile game players. It contains a large number of popular game resources and rich game-related functions. Below, the editor will introduce the game controller connection method. Players, please take a look. 1. First go to the homepage of Gohan Game Center APP, and then click the "My" option in the lower right corner of the homepage; 2. Find the [Controller] function in the My page, the location is shown in the picture below, and click to go to settings; 3. Select to turn it on For the Bluetooth function of the mobile phone, confirm that the power of the controller is on; 4. Finally, follow the instructions of the controller to make a matching connection. If the connection is successful, you can use the mobile game to experience various games.

How to connect keep to Huawei bracelet How to connect keep to Huawei bracelet Mar 07, 2024 pm 09:46 PM

How to connect keep to Huawei bracelet? You can connect Huawei bracelet in keep software. Most users don’t know how to connect Huawei bracelet. Next is the graphic tutorial of how to connect keep to Huawei bracelet brought by the editor. Interested users come and take a look! How to connect keep to Huawei bracelet 1. First open the keep application, click [Me] in the lower right corner of the main page to enter the special area, and select [Smart Hardware]; 2. Then challenge to the My Smart Device function page, click [Add Device] in the middle; 3. Then on the page of selecting the device you want to add, select the [Smart Bracelet/Watch] function; 4. Finally, on the interface shown below, click on the Huawei watch model to connect.

How to check if a string starts with a specific character in Golang? How to check if a string starts with a specific character in Golang? Mar 12, 2024 pm 09:42 PM

How to check if a string starts with a specific character in Golang? When programming in Golang, you often encounter situations where you need to check whether a string begins with a specific character. To meet this requirement, we can use the functions provided by the strings package in Golang to achieve this. Next, we will introduce in detail how to use Golang to check whether a string starts with a specific character, with specific code examples. In Golang, we can use HasPrefix from the strings package

Three Ways to Fix Edge Your Connection Isn't Private Three Ways to Fix Edge Your Connection Isn't Private Mar 13, 2024 pm 01:30 PM

When you use the Edge browser to access web pages, have you ever encountered a prompt that your connection is not a dedicated connection, causing web browsing to fail? How is this going? Many friends don’t know how to deal with this problem. You can take a look at the following three solutions. Method 1 (simple and crude): In the edge browser, you can try to solve the problem of the website being inaccessible by entering the settings and turning off the security function, and then blocking location permissions in the website permissions. It is important to note that the effectiveness and duration of this approach may vary, and specific effects cannot be determined. After restarting your browser, you can try visiting the website to see if the issue is resolved. Method 2: Adjust the keyboard to English input

See all articles