Click here to Skip to main content
15,888,044 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i download a project in a website its built by visaul studio asp.net and C#.net and sql server 2005

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;

namespace Server
{
    class Class1
    {

        string constring = Convert.ToString(ConfigurationSettings.AppSettings["ConnectionString"]);
        SqlCommand cmd1, cmd2, c, c1, cmd3,cmd7;
        string id, id1, id2, id3, id4;
        int eid, eid1, eid2, eid3, eid4;

        public int idgeneration()
        {
            SqlConnection con = new SqlConnection(constring);
            con.Open();
            SqlCommand c1;
            c1 = new SqlCommand("select max(ID) from Registration", con);
            id = Convert.ToString(c1.ExecuteScalar());
            if (id == "")
            {
                eid = 1;
            }
            else
            {
                eid = Convert.ToInt16(id);
                eid = eid + 1;
            }
            con.Close();
            return eid;
        }

        public int uploadfileid()
        {
            SqlConnection con1 = new SqlConnection(constring);
            con1.Open();
            SqlCommand c1;
            c1 = new SqlCommand("select max(fileid) from uploadfiles", con1);
            id1 = Convert.ToString(c1.ExecuteScalar());
            if (id1 == "")
            {
                eid1 = 1;
            }
            else
            {
                eid1 = Convert.ToInt16(id1);
                eid1 = eid1 + 1;
            }
            con1.Close();
            return eid1;
        }



        public int senditems()
        {
            SqlConnection con1 = new SqlConnection(constring);
            con1.Open();
            SqlCommand c1;
            c1 = new SqlCommand("select max(Req_ID) from senditems", con1);
            id1 = Convert.ToString(c1.ExecuteScalar());
            if (id1 == "")
            {
                eid1 = 1;
            }
            else
            {
                eid1 = Convert.ToInt16(id1);
                eid1 = eid1 + 1;
            }
            con1.Close();
            return eid1;
        }



        public int autoid()
        {
            SqlConnection con4 = new SqlConnection(constring);
            con4.Open();
            SqlCommand c5;
            c5 = new SqlCommand("select max(autid) from usersearch", con4);
            id2 = Convert.ToString(c5.ExecuteScalar());
            if (id2 == "")
            {
                eid2 = 1;
            }
            else
            {
                eid2 = Convert.ToInt16(id2);
                eid2 = eid2 + 1;
            }
            con4.Close();
            return eid2;
        }
        public void uploadfile(string fid, string finame, byte[] File, string time, string path1,string ext)
        {

            SqlConnection con2 = new SqlConnection(constring);
            con2.Open();
            int n = finame.Length;
            cmd2 = new SqlCommand("insert into uploadfiles values('" + fid + "','" + finame + "',@File,'" + time + "','" + path1 + "','"+ext+"')", con2);
            cmd2.Parameters.AddWithValue("@File", File);
            cmd2.ExecuteNonQuery();
            con2.Close();
        }





        public void senditems(string reqid, string sendid, string fname, byte[] File, string uname, string userip, string send)
        {

            SqlConnection con7 = new SqlConnection(constring);
            con7.Open();
            int n = fname.Length;
            cmd7 = new SqlCommand("insert into senditems values('" + reqid + "','" + sendid + "','" + fname + "',@File,'" + uname + "','" + userip + "','"+send+"')", con7);
            cmd7.Parameters.AddWithValue("@File", File);
            cmd7.ExecuteNonQuery();
            con7.Close();
        }



       
        public void usersearch(string auid, string reqid, string usrid, string unam, string filnm, string dat, string sta)
        {
            SqlConnection con3 = new SqlConnection(constring);
            con3.Open();
            cmd3 = new SqlCommand("insert into usersearch values('" + auid + "','" + reqid + "','" + usrid + "','" + unam + "','" + filnm + "','" + dat + "','Key not send')", con3);
            cmd3.ExecuteNonQuery();
            con3.Close();
        }
        public void keymaintain(string aid, string reqid, string usrid, string secretky, string path, string path1)
        {
            SqlConnection con4 = new SqlConnection(constring);
            con4.Open();
            cmd1 = new SqlCommand("insert into keymaintenance values('" + aid + "','" + reqid + "','" + usrid + "','" + secretky + "','" + path + "','')", con4);
            cmd1.ExecuteNonQuery();
            con4.Close();
        }


    }

}


What I have tried:

C++
problem on connecting string so please help me how to connect
Posted
Updated 17-Feb-18 23:29pm
Comments
RickZeeland 18-Feb-18 2:35am    
What kind of SQL Server database are you using, localDb, Express or standard ?
What kind of authentication are you using for the database, windows or Sql Server authentication ?
johndevmars 18-Feb-18 5:23am    
sql its express edition -2008

windows authentication

C#
cmd3 = new SqlCommand("insert into usersearch values('" + auid + "','" + reqid + "','" + usrid + "','" + unam + "','" + filnm + "','" + dat + "','Key not send')", con3);

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
Share this answer
 
Example connection string for SQL Server Express with Windows authentication:
Connection Timeout=2;Integrated Security=SSPI;Persist Security Info=False;Data Source=MyPCname\SQLEXPRESS;Initial Catalog=MyDatabase
Replace MyPCname with the name of your PC or (local), replace MyDatabase with the name of your database.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900