有一种方法,我们可以解析任何用户输入的时间。。。
在这里,我从文本文件中获取连接字符串的输入
我假设将此字符串保存在文本文件中的用户是可信的。
但是如果他在不知情的情况下犯了一个错误,会导致接下来的代码导致异常,
我想要一种检查字符串格式是否正确的方法,比如用某种方法解析它,看看它是否是连接字符串应该是的方式,然后可能使用解析的结果。
编辑
根据请求,我使用的示例代码和sqladapter使用的连接
//Connect to a remote instance of SQL Server.
Server srv;
ServerConnection conContext = new ServerConnection();
conContext.ServerInstance = @"A-63A9D4D7E7934\SECOND";
conContext.LoginSecure = false;
conContext.Login = "sa";
conContext.Password = "two";
srv = new Server(conContext);
Response.Write(srv.Information.Version);
//Data Source=A-63A9D4D7E7834\SECOND;Initial Catalog=replicate;User ID=sa;Password=***********