Data source and Initial Catalog

Source: Internet
Author: User

What is the difference between initial catalog and database?
Initial Catalog:
DataBase:
There is no difference between the two, just the name is different, it is like the real name of the human being with the same name. Can call you.

********************************************

Integrated Security=sspi This indicates that the current Windows system user is logged on to the SQL Server server and an error occurs if the SQL Server server does not support this way of logging on.
You can log in using the user name and password for SQL Server, such as:
"Provider=SQLOLEDB.1; Persist Security info=false;initial catalog= database name; Data source=192.168.0.1; User Id=sa; password= Password "


***************************************************

Integrated Security-or-trusted_connection ' false ' when false, a user ID and password will be specified in the connection. When True, the current Windows account credentials are used for authentication. The recognized values are true, false, yes, no, and SSPI, which is equivalent to true (highly recommended).


*************************************************

How to connect a database in ADO
System.Data.SqlClient.SqlConnection
Some common connection strings (C # code):

SqlConnection conn = new SqlConnection ("server= (local); Integrated security=sspi;database=pubs");

SqlConnection conn = new SqlConnection ("server= (local) \netsdk;database=pubs;integrated Security=sspi");

SqlConnection conn = new SqlConnection ("Data source=localhost;integrated security=sspi;initial catalog=northwind;");

SqlConnection conn = new SqlConnection ("Data source= (local); initial catalog=xr;integrated Security=sspi;
Persist Security Info=false;workstation Id=xurui;packet size=4096; “);

SqlConnection myconn = new System.Data.SqlClient.SqlConnection ("Persist Security info=false;integrated
Security=sspi;database=northwind;server=mysqlserver ");

SqlConnection conn = new SqlConnection ("Uid=sa;pwd=passwords;initial catalog=pubs;data source=127.0.0.1; Connect timeout=900 ");

Region "Private Variable"

<summary>

Represents an open connection to a database

</summary>

Private System.Data.SqlClient.SqlConnection Con = new SqlConnection ();

<summary>

Indicates whether the execution object is SQL or stored procedure

</summary>

Private System.Data.SqlClient.SqlCommand CMD = new SqlCommand ();

<summary>

Represents a set of data commands and connections to a database that are used to populate System.Data.DataSet and update databases

</summary>

Private System.Data.SqlClient.SqlDataAdapter dtapt = new SqlDataAdapter ();

<summary>

Represents a transaction to be generated in the database

</summary>

Private System.Data.SqlClient.SqlTransaction Sqltran;

<summary>

Provides a way to read a forward-only stream of data rows from a data source

</summary>

Private SqlDataReader dtrvalue = null;

#endregion

#region "Database connection Processing"

<summary>

Get the default SQL connection string in Webconfig

</summary>

private String Strconsql

{

Get

{

return system.configuration.configurationmanager.appsettings["Sqlconntionstr"]. ToString ();

}

}

#endregion

#region "Transaction Processing"

<summary>

Start a transaction

</summary>

public void BeginTransaction ()

{

if (con.state = = connectionstate.closed)

{

Open connection

OPENCN ();

Start a transaction

if (Sqltran = = null)

{

Sqltran = Con.begintransaction ();

}

Cmd.transaction = Sqltran;

}

}

<summary>

Commit a transaction

</summary>

public void Committransection ()

{

Sqltran.commit ();

Sqltran.dispose ();

Sqltran = null;

CLOSECN ();

}

<summary>

Rolling back a transaction

</summary>

public void Rollbacktransection ()

{

Sqltran.rollback ();

Sqltran.dispose ();

Sqltran = null;

CLOSECN ();

}

#endregion

#region "return page table Data datatable [Read] way to get data, the amount of data proposed in the query results in 10,000 records"

<summary>

For pagination control, returns the number of data and record bars that need to display the page

</summary>

<param name= "P_strsql" >sql statement </param>

<param name= "p_cmdparms" >sql parameters and their corresponding values </param>

<param name= "P_intstart" > Start record </param>

<param name= "P_intpagesize" > number of Record bars per page </param>

<param name= "Out_intcount" > return record number of bars </param>

<returns> Querying Datasets </returns>

Protected DataTable executereadtable (String p_strsql, sqlparameter[] p_cmdparms, int p_intstart, int p_intpagesize, ref i NT Out_intcount)

{

Return executereadtable (CommandType.Text, P_strsql, P_cmdparms, P_intstart, p_intpagesize, ref out_intcount);

}

<summary>

1. DataTable values are worth according to stored procedures and parameters

2. Get a DataTable value based on SQL

</summary>

<param name= "P_objcmdtype" > is a stored procedure or sql</param>

<param name= "P_intstart" > Start record </param>

<param name= "P_intpagesize" > shows the number of bars per page </param>

<param name= "P_strsql" > But SQL can also be a stored procedure </param>

<param name= "p_cmdparms" >sqlparameter parameter list </param>

<param name= "Out_intcount" > Return total Records </param>

<returns> Back to Datatable</returns>

Protected DataTable executereadtable (CommandType p_objcmdtype, String p_strsql, sqlparameter[] p_cmdparms, int p_ Intstart, int p_intpagesize, ref int out_intcount)

{

DataTable DTB = new DataTable ();

DateTime Dtstart = DateTime.Now;

Dtrvalue = ExecuteReader (P_objcmdtype, P_strsql, p_cmdparms);

if (Dtrvalue = = null)

{

CLOSECN ();

return DTB;

}

int intcollength = Dtrvalue.fieldcount;

for (int i = 0; i < intcollength; i++)

{

table that constructs SQL

DtB. Columns.Add (Dtrvalue.getname (i), Getcoltype (i));

}

DataRow Dr;

int k = 0;

if (dtrvalue.hasrows)

{

Reading data row values

while (Dtrvalue.read ())

{

Reading between paging data

if (P_intstart <= k && k < P_intstart + p_intpagesize)

{

Dr = DtB. NewRow ();

Read each column value

for (int j = 0; J < Intcollength; J + +)

{

Read values for each column

Dr[dtrvalue.getname (j)] = GetValue (J, GetFieldType (j). ToString ());

}

DtB. Rows.Add (DR);

}

k++;

}

Delete the current page all data then read the previous page of data

if (k <= p_intstart)

{

while (K <= P_intstart)

{

P_intstart = p_intstart-p_intpagesize;

}

k = 0;

Dtrvalue = ExecuteReader (P_objcmdtype, P_strsql, p_cmdparms);

if (dtrvalue.hasrows)

{

while (Dtrvalue.read ())

{

Reading between paging data

if (P_intstart <= k && k < P_intstart + p_intpagesize)

{

Dr = DtB. NewRow ();

Read each column value

for (int j = 0; J < Intcollength; J + +)

{

Read values for each column

Dr[dtrvalue.getname (j)] = GetValue (J, GetFieldType (j). ToString ());

}

DtB. Rows.Add (DR);

}

k++;

}

}

}

}

CLOSECN ();

Sehr. Bll. Function.AddSQLLog.WriteLog (P_strsql, dtStart.TimeOfDay.ToString (), DateTime.Now.TimeOfDay.ToString (), Convert.ToString (Datetime.now-dtstart));

if (Out_intcount = = 0)

{

Out_intcount = k;//Gets the total number of rows and returns to the page

}

return DTB;

}

#endregion

#region "ExecuteReader Execute SQL statement"

<summary>

ExecuteReader

</summary>

<param name= "p_objcmdtype" > Command type 1commandtype.text SQL statements 2commandtype.storedprocedure stored procedures </param>

<param name= "p_strsql" > Command Type 1 SQL statement 2 stored procedure name </param>

<param name= "P_cmdparms" >SqlParameter</param>

<returns>SqlDataReader</returns>

Private SqlDataReader ExecuteReader (CommandType p_objcmdtype, String p_strsql, sqlparameter[] p_cmdparms)

{

SqlDataReader Dtrret = null;

Try

{

Open connection

OPENCN ();

Command line connection

Cmd.connection = Con;

Cmd.commandtext = P_strsql;

is an SQL statement or a stored procedure

Cmd.commandtype = P_objcmdtype;

Cyclic cmdparms value

if (p_cmdparms! = null)

{

foreach (SqlParameter objparm in p_cmdparms)

{

CMD.PARAMETERS.ADD (Objparm);

}

}

Dtrret = Cmd.executereader ();

Cmd.Parameters.Clear ();

return dtrret;

}

catch (Exception e)

{

String strerr = String. Empty; P_cmdparms parameter values

if (p_cmdparms! = null)

{

foreach (SqlParameter objparm in p_cmdparms)

{

Strerr + = objparm.parametername + "=" + Objparm.value + "'";

}

}

if (con.state! = connectionstate.closed && Sqltran = = null)

{

Cmd.Parameters.Clear ();

CLOSECN ();

}

Write error log

Sehr. Bll. Function.AddMsgLog.AddError ("SQLBase", E.message + "" N "R SQL:" + p_strsql + "" n "R parameter:" + Strerr, e.stacktrace);

return null;

}

Finally

{

Close the connection if the connection is open and there are no transactions and SqlDataReader events

if (con.state! = connectionstate.closed && Sqltran = = NULL && Dtrret = = null)

{

Cmd.Parameters.Clear ();

CLOSECN ();

}

}

}

#endregion

Data source and Initial Catalog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.