| |

VerySource

 Forgot password?
 Register
Search
View: 1734|Reply: 13

web.config database connection error

[Copy link]

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Unknown

Post time: 2020-3-19 12:30:01
| Show all posts |Read mode
Use strConn in SqlConnection myconn = new SqlConnection (strConn);
"Server = ZEMU-A12\COMPANY; UID = zbr; PWD = # szzemucompany #; Database = dbok" instead of running without problems, but if you read <add key = "strConnString" value = "Server = ZEMU-A12\COMPANY ; UID = zbr; PWD = # szzemucompany #; Database = dbok "> </ add> When the value of strConnString is reported, an" instance failed "error is reported, ask the reason
   protected static string strConn = System.Configuration.ConfigurationManager.AppSettings ["strConnString"];
        
        public static int ExecuteSql (string strSql)
        {
            SqlConnection myconn = new SqlConnection (strConn);
            SqlCommand mycomm = new SqlCommand (strSql, myconn);
            try
            {
                myconn.Open ();
                mycomm.ExecuteNonQuery ();
                return 0;
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                throw new Exception (e.Message);
            }
            finally
            {
                mycomm.Dispose ();
                myconn.Close ();
            }
        }

Web.Config file contents:

<? xml version = "1.0" encoding = "utf-8"?>
<configuration>
  <appSettings>
    <add key = "strConnString" value = "Server = ZEMU-A12\COMPANY; UID = zbr; PWD = # szzemucompany #; Database = dbok"> </ add>
    <add key = "WebSiteVersion" value = "Ver1.0"> </ add>
    <add key = "WebManger" value = "Windxf"> </ add>
  </ appSettings>
</ configuration>
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

Post time: 2020-6-24 10:00:02
| Show all posts
<add key="strConnString" value="Server=ZEMU-A12\COMPANY;UID=zbr;PWD=#szzemucompany#;Database=dbok"></add>

The following </add> is directly replaced with />Try it out
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-6-24 14:00:01
| Show all posts
No, it's the same error
Reply

Use magic Report

0

Threads

25

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-6-24 21:00:02
| Show all posts
protected static string strConn = System.Configuration.ConfigurationManager.AppSettings["strConnString"];
Replace with
protected static string strConn = System.Configuration.ConfigurationSettings.AppSettings["strConnString"];
Try
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-6-24 23:15:01
| Show all posts
Is there a problem with the incoming Japanese SQL statement?
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-6-25 20:30:01
| Show all posts
protected static string strConn = System.Configuration.ConfigurationSettings.AppSettings["strConnString"];
Agree with this method but introduce a namespace, check it and you will know
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-26 10:45:01
| Show all posts
strConn=ConfigurationSettings.AppSettings("strConnString")
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-7-7 21:30:01
| Show all posts
protected static string strConn = System.Configuration.ConfigurationSettings.AppSettings["strConnString"];


In fact, I used the above method before, the namespace was also introduced, or the error of the reported instance failure, I later changed to

protected static string strConn = System.Configuration.ConfigurationManager.AppSettings["strConnString"];
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-7-9 14:45:01
| Show all posts
<configuration>
  <appSettings>
    <add key="conString"
     value="Server=localhost;UID=sa;PWD=secret;Database=Northwind" />
  </appSettings>
</configuration>

-------------------------
string strConString = ConfigurationSettings.AppSettings[ "conString" ];
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-7-11 18:30:01
| Show all posts
Boss, it still doesn't work
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list