摘抄的SQL Server和Access的ConnectionString

 SQL Server

    •  ODBC

      •  Standard Security:
        "Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"


      •  Trusted connection:
        "Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;"


      •  Prompt for username and password:
        oConn.Properties("Prompt") = adPromptAlways
        oConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;"

       

    •  OLE DB, OleDbConnection (.NET)


    •  Standard Security:
      "Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"


    •  Trusted connection:
      "Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;"


    •  Prompt for username and password:
      oConn.Properties("Prompt") = adPromptAlways
      oConn.Open "Driver={SQL Server};Server=Aron1;DataBase=pubs;"




    •  Standard Security:
      "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"


    •  Trusted Connection:
      "Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
      (use serverName/instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
    •  Prompt for username and password:
      oConn.Provider = "sqloledb"
      oConn.Properties("Prompt") = adPromptAlways
      oConn.Open "Data Source=Aron1;Initial Catalog=pubs;"


    •  Connect via an IP address:
      "Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
      (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))


 SqlConnection (.NET)

  •  Standard Security:
    "Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"
       - or -
    "Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False"
       (both connection strings produces the same result)


  •  Trusted Connection:
    "Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
       - or -
    "Server=Aron1;Database=pubs;Trusted_Connection=True;"
       (both connection strings produces the same result)
    (use serverName/instanceName as Data Source to use an specifik SQLServer instance, only SQLServer2000)
  •  Connect via an IP address:
    "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
    (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
  •  Declare the SqlConnection:
    C#:
    using System.Data.SqlClient;
    SqlConnection oSQLConn = new SqlConnection();
    oSQLConn.ConnectionString="my connection string";
    oSQLConn.Open();
    VB.NET:
    Imports System.Data.SqlClient
    Dim oSQLConn As SqlConnection = New SqlConnection()
    oSQLConn.ConnectionString="my connection string"
    oSQLConn.Open()


 

 SQL Server 2005

    •  SQL Native Client ODBC Driver
    •  SQL Native Client OLE DB Provider
    •  SqlConnection (.NET)


    •  Standard security:
      "Driver={SQL Native Client};Server=Aron1;Database=pubs;UID=sa;PWD=asdasd;"


    •  Trusted connection:
      "Driver={SQL Native Client};Server=Aron1;Database=pubs;Trusted_Connection=yes;"
      Equivalents
      Integrated Security=SSPI equals Trusted_Connection=yes
    •  Prompt for username and password:
      oConn.Properties("Prompt") = adPromptAlways
      oConn.Open "Driver={SQL Native Client};Server=Aron1;DataBase=pubs;"


    •  Enabling MARS (multiple active result sets):
      "Driver={SQL Native Client};Server=Aron1;Database=pubs;Trusted_Connection=yes;MARS_Connection=yes"
      Equivalents
      MultipleActiveResultSets=true equals MARS_Connection=yes

      Using MARS with SQL Native Client, by Chris Lee >>
    •  Encrypt data sent over network:
      "Driver={SQL Native Client};Server=Aron1;Database=pubs;Trusted_Connection=yes;Encrypt=yes"
      Download the SQL Native Client here >> (the package contains booth the ODBC driver and the OLE DB provider)


    •  Standard security:
      "Provider=SQLNCLI;Server=Aron1;Database=pubs;UID=sa;PWD=asdasd;"


    •  Trusted connection:
      "Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;"
      Equivalents
      Integrated Security=SSPI equals Trusted_Connection=yes
    •  Prompt for username and password:
      oConn.Properties("Prompt") = adPromptAlways
      oConn.Open "Provider=SQLNCLI;Server=Aron1;DataBase=pubs;"


    •  Enabling MARS (multiple active result sets):
      "Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;MarsConn=yes"
      Equivalents
      MarsConn=yes equals MultipleActiveResultSets=true equals MARS_Connection=yes

      Using MARS with SQL Native Client, by Chris Lee >>
    •  Encrypt data sent over network:
      "Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;Encrypt=yes"
      Download the SQL Native Client here >> (the package contains booth the OLE DB provider and the ODBC driver)


    •  Standard Security:
      "Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"
         - or -
      "Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False"
         (both connection strings produces the same result)


    •  Trusted Connection:
      "Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
         - or -
      "Server=Aron1;Database=pubs;Trusted_Connection=True;"
         (both connection strings produces the same result)
      (use serverName/instanceName as Data Source to use an specifik SQLServer instance)
    •  Connect via an IP address:
      "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
      (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
    •  Enabling MARS (multiple active result sets):
      "Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=true"
      Note! Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1

      Streamline your Data Connections by Moving to MARS, by Laurence Moroney, DevX.com >>
  •  
  •  
  •  Access
      •  ODBC
      •  OLE DB, OleDbConnection (.NET)


      •  Standard Security:
        "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Uid=Admin;Pwd=;"


      •  Workgroup:
        "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;SystemDB=C:/mydatabase.mdw;"


      •  Exclusive:
        "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/mydatabase.mdb;Exclusive=1;Uid=admin;Pwd="




      •  Standard security:
        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;User Id=admin;Password=;"


      •  Workgroup (system database):
        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;Jet OLEDB:System Database=system.mdw;"


      •  With password:
        "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=/somepath/mydb.mdb;Jet OLEDB:Database Password=MyDbPassword;"
### 回答1: 这个错误通常是由于连接字符串未正确设置或未被初始化引起的。你需要检查你的代码,确保连接字符串已经被正确地设置,并且在使用它之前已经被初始化。 如果你在应用程序中使用了配置文件,你需要确保连接字符串已经被正确地配置并且在应用程序启动时已经被加载。 如果你仍然无法解决问题,请提供更多信息,例如你的连接字符串设置以及出现错误的代码段,这样我才能更精确地帮助你解决这个问题。 ### 回答2: 首先,需要明确"SQL Server Connection String"是指用于在代码中连接到SQL Server数据库的字符串。当我们要连接SQL Server数据库时,需要提供一些必要的信息,例如服务器的地址、数据库的名称、用户名和密码等。这些信息被组合成一个字符串,称为"Connection String"。 在代码中,当我们尝试连接SQL Server数据库时,我们需要将此连接字符串传递给相关的连接对象。由于它是连接数据库的关键信息,所以我们在使用它之前必须对其进行初始化。如果我们尚未对连接字符串进行初始化或者在连接之前没有为其分配一个正确有效的值,就会出现"SQL Server ConnectionString尚未初始化"的错误。 要解决这个问题,我们需要确保在使用连接字符串之前进行初始化并为其分配正确有效的值。具体方法如下: 1. 在代码的适当位置,创建一个新的连接字符串变量。 2. 格式化连接字符串以符合SQL Server数据库的要求。确保提供正确的服务器地址、数据库名称以及必要的身份验证信息。 3. 将正确有效的连接字符串赋值给创建的连接字符串变量。 4. 确保在将连接字符串传递给连接对象时,连接字符串变量已经经过正确的初始化。 总而言之,要解决"SQL Server ConnectionString尚未初始化"的错误,我们需要对连接字符串进行正确有效的初始化,并在代码中正确地使用它。这将确保成功连接到SQL Server数据库并执行相关的数据库操作。 ### 回答3: "SQL Server connection string尚未初始化"指的是在使用SQL Server连接字符串之前,没有对其进行初始化或赋值的情况。 在使用SQL Server进行数据库连接时,需要使用连接字符串来指定连接的服务器名称、身份验证信息、数据库名称等相关信息。连接字符串是一个包含连接信息的字符串,它告诉应用程序如何连接到SQL Server数据库。 要解决这个问题,我们需要在使用连接字符串之前,先对其进行初始化或赋值。具体的做法如下: 1. 找到应用程序中需要连接数据库的部分。 2. 在这部分代码中,找到并确保已经创建了一个连接字符串变量或对象,类似于以下的形式: string connectionString = "Data Source=...;Initial Catalog=...;User ID=...;Password=...;"; 或者使用.NET框架提供的SqlConnection类和相关属性来创建连接字符串,例如: SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); builder.DataSource = "..."; builder.InitialCatalog = "..."; builder.UserID = "..."; builder.Password = "..."; string connectionString = builder.ToString(); 3. 确保连接字符串中的各个参数已经正确设置,包括数据源(服务器名称)、初始目录(数据库名称)、登录用户名和密码等。 4. 在使用连接字符串之前,将其赋值给相应的数据库连接对象。 通过以上步骤,您应该能够成功初始化SQL Server连接字符串,解决"SQL Server connection string尚未初始化"的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值