请问出现 
从索引 34 处 开始 ,初始化字符串的格式不符合规范
  该怎么解决?
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;namespace Reg
{
    class Conn
    {
        private string IP;
        private string DbName;
        private string DbUser;
        private string Key;
        public Conn(string ip, string dbName, string dbUser, string key)
        {
            IP = ip;
            DbUser = dbUser;
            DbName = dbName;
            Key = key;
        }
        public SqlConnection creatConn()
        {
            SqlConnection thisConnection = new SqlConnection(@"Server=" + IP + ";user id=" + DbUser + ";initial catalog=" + DbName + ";password" + Key);
            thisConnection.Open();
            return thisConnection;
        }
    }
}

解决方案 »

  1.   

    password=" + Key
      

  2.   

    SqlConnection thisConnection = new SqlConnection(@"Server=" + IP + ";user id='" + DbUser + "';initial catalog=" + DbName + ";password='" + Key+"');
      

  3.   

    SqlConnection thisConnection = new SqlConnection(@"Server=" + IP + ";user id='" + DbUser + "';initial catalog=" + DbName + ";password='" + Key+"'");最后还加一个双引号。
      

  4.   


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data.SqlClient;namespace TestDB
    {
        class Conn
        {
            private string IP;
            private string DbName;
            private string DbUser;
            private string Key;        public Conn(string ip, string dbName, string dbUser, string key)
            {
                IP = ip;
                DbName = dbName;
                DbUser = dbUser;
                Key = key;
            }
           
            public SqlConnection creatConn()
            {
                SqlConnection thisconnection = new SqlConnection(@"Server=" + IP + ";user id=" + DbUser + ";initial catalog=" + DbName + ";password=" + Key);            thisconnection.Open();
                return thisconnection;
            }
        }
    }
      

  5.   

    呵呵,也可以用SqlConnectionStringBuilder来一个个指定属性。
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Data.SqlClient;namespace TestDB
    {
        class Conn
        {
            private string IP;
            private string DbName;
            private string DbUser;
            private string Key;        public Conn(string ip, string dbName, string dbUser, string key)
            {
                IP = ip;
                DbName = dbName;
                DbUser = dbUser;
                Key = key;
            }
           
            public SqlConnection creatConn()
            {
                SqlConnection thisconnection = new SqlConnection(@"Server=" + IP + ";user id=" + DbUser + ";initial catalog=" + DbName + ";password=" + Key);            thisconnection.Open();
                return thisconnection;
            }
        }
    }
      

  7.   

    ...怎么不会设置颜色了上边的代码,注意SqlConnection thisconnection = new SqlConnection(@"Server=" + IP + ";user id=" + DbUser + ";initial catalog=" + DbName + ";password=" + Key);
    我也用过。是一本书上的代码。红色封面的,清华大学出版社的。。
      

  8.   

    SqlConnection thisConnection = new SqlConnection("Server=" + IP + ";user id=" + DbUser + ";initial catalog=" + DbName + ";password=" + Key); 
                thisConnection.Open(); 
      

  9.   

    你肯定是要调用SQL里的表的数据来进行登录。
    可能要在SQL Server中定义那个字符。比如:select @return=count(*) from 表名称 where UserName=@user and Pwd=@pwd
    也许可以
      

  10.   

    SqlConnection thisConnection = new SqlConnection(@"Server=" + IP + ";user id=" + DbUser + ";initial catalog=" + DbName + ";password=" + Key);连接数据库的代码最好还是在web.config里配置
    无论是安全性还是简易型更好些
    <configuration>
    <connectionStrings>
    <add name="oracle_Conn" connectionString="Data Source=iagent;User ID=sa;Password=ia;Unicode=True" providerName="System.Data.OracleClient"/>
    </connectionStrings>