.Net Webconfig连接字符串中数据库实例名带'\'的问题

时间:2023-03-09 16:18:24
.Net Webconfig连接字符串中数据库实例名带'\'的问题

获取前:

.Net Webconfig连接字符串中数据库实例名带'\'的问题

获取后:

.Net Webconfig连接字符串中数据库实例名带'\'的问题

导致sa登录失败的问题

string strCon = "workstation id=localhost;packet size=4096;user id=" + user + ";data source=" + dbserver + ";persist security info=True;password=";

//判断数据库实例名中是否包含字符串'\',如果包含'\'的话,替换'\\'为'\'

if (strCon.Contains(@"\"))
                                            {
                                                _node.Item(i).Attributes.GetNamedItem("value").InnerText = strCon.Replace(@"\\",@"\");
                                            }
                                            else
                                            {
                                                _node.Item(i).Attributes.GetNamedItem("value").InnerText = strCon;
                                            }