问题描述
publicSqlDataReaderGetList(stringSql){SqlConnectionmyConnection=newSqlConnection(Db.ConnectionString);SqlCommandmyCommand=newSqlCommand(Sql,myConnection);myConnection.Open();SqlDataReaderresult=myCommand.ExecuteReader(CommandBehavior.CloseConnection);returnresult;}其中“SqlConnectionmyConnection=newSqlConnection(Db.ConnectionString);”老提示索引90后,初始化字符串的格式不符合规范,请大侠帮帮小弟吧
解决方案
解决方案二:
显然是连接字符串没写对.自己查http://connectionstrings.com/
解决方案三:
字符串不对stringConnectionString="datasource=localhost;initialcatalog=DatabaseName;integratedsecurity=SSPI;userID=sa;password=123456";
解决方案四:
Db.ConnectionString是从哪里读取的,查看原链接字符串是否正确!字符串连接如楼上的。
解决方案五:
publicSqlDataReaderGetList(stringSql){stringConnectionString="datasource=localhost;initialcatalog=DatabaseName;integratedsecurity=SSPI;userID=sa;password=123456";SqlConnectionmyConnection=newSqlConnection(ConnectionString);SqlCommandmyCommand=newSqlCommand(Sql,myConnection);myConnection.Open();SqlDataReaderresult=myCommand.ExecuteReader(CommandBehavior.CloseConnection);returnresult;}
解决方案六:
publicclassDatabase{protectedstringstrconnection;protectedSqlConnectionconn;publicDatabase(){strconnection=ConfigurationManager.ConnectionStrings["zilong"].ConnectionString;}protectedvoidOpen()//保护方法,打开连接{if(conn==null){conn=newSqlConnection(strconnection);}if(conn.State.Equals(ConnectionState.Closed)){conn.Open();}}publicvoidClose(){if(conn.State.ToString()=="Open"){conn.Close();}}publicSqlDataReaderGetList(stringSql){Open();SqlDataReaderresult=myCommand.ExecuteReader(CommandBehavior.CloseConnection);returnresult;}
解决方案七:
引用4楼jiang_jiajia10的回复:
C#codepublicSqlDataReaderGetList(stringSql){stringConnectionString="datasource=localhost;initialcatalog=DatabaseName;integratedsecurity=SSPI;userID=sa;password=123456";SqlConnectionmyConnection=newSqlConnection(ConnectionString);SqlCommandmyCommand=newSqlCommand(Sql,myConnection);myConnection.Open();SqlDataReaderresult=myCommand.Execute…
顶