| |

VerySource

 Forgot password?
 Register
Search
View: 758|Reply: 7

Help! VS SQL Server database connection problem

[Copy link]

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 Invalid IP Address

Post time: 2020-3-9 18:30:01
| Show all posts |Read mode
I only have vs on this computer, and SQL Server is on another host on the local LAN. I want to connect VS to SQL Server on the host. How do I write the connection string?
PS: I checked. Many people use driver online, but it does n’t support
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-5-31 07:30:02
| Show all posts
public partial class kaipiaoziliao_loginpage: System.Web.UI.Page
{
    protected void Page_Load (object sender, EventArgs e)
    {

    }
    protected void Button1_Click (object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection ();
        con.ConnectionString = "Server = i-server; database = fapiao; integrated security = SSPI;";
        
        SqlCommand objcmd = new SqlCommand ();
        objcmd.Connection = con;
        objcmd.CommandText = "select shuihao from cheeck where shuihao = '" + Convert.ToInt32 (TextBox1.Text.Trim ()) + "'";
        con.Open ();
        SqlDataReader dr = objcmd.ExecuteReader ();
        if (dr.Read ())
        {
            Session ["shuihao"] = TextBox1.Text.Trim ();
            Response.Redirect ("cheeck.aspx");
        }
        else
        {Response.Write ("<script language = 'javascript'> window.alert ('Your input is incorrect, please re-enter!'); </ Script>");}
    }
 
}
The above is my program segment, but SqlDataReader dr = objcmd.ExecuteReader () appears at runtime; is this line of error, is it because the database is not connected?
Reply

Use magic Report

0

Threads

26

Posts

20.00

Credits

Newbie

Rank: 1

Credits
20.00

 China

Post time: 2020-5-31 12:30:02
| Show all posts
SqlConnection conn = new SqlConnection ("Data Source = .\\SQLEXPRESS; database = DB2015; Integrated Security = True");
            string sql = "";
            SqlDataAdapter da = new SqlDataAdapter (sql, conn);
            DataTable dt = new DataTable ();
            da.Fill (dt);
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-5-31 15:00:01
| Show all posts
If you ca n’t connect

con.Open (); This should be an error,

It should be a problem with sql, check it out.
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-6-1 05:15:02
| Show all posts
Is the data source followed by the IP of the host? Is it necessary to add the port number? How to see the port number?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-2 23:30:01
| Show all posts
Connection string problem
private string connectionstring = "server=ZHANGYAHUI\\SQLEXPRESS;uid=sa;pwd=sa;database=Student";
Reply

Use magic Report

3

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

 Author| Post time: 2020-6-3 23:00:01
| Show all posts
I changed the connection string to con.ConnectionString = "data source=192.168.0.1;database=fapiao;integrated security=SSPI";
192.168.0.1 is the IP of the local host, but it still does not work, or it still prompts "SqlDataReader dr = objcmd.ExecuteReader();" This error, what to do???
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-6-6 13:15:01
| Show all posts
Drag a SqlConnection to use the IDE's connection wizard to generate one!
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