Hallo,
ich habe eine Klasse programmiert, die eine Verbindung zur Datenbank und SQl-Abfragen verwaltet.
Leider bekomme ich einen Fehler beim Compilieren.
QoSRoboter_DatenbankVerbindung.GetconnectionStrin(string,string): Nicht alle Codfelder geben einen Wert zurück.
Es geht um die Methode GetConnectionString
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67:
| using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Configuration;
public class QoSRoboter_DatanbankVerbindung { public QoSRoboter_DatanbankVerbindung() { } public System.Data.SqlClient.SqlConnection GetConnectionString(string SQLServer, string SQLTable) { try { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" + SQLTable + ";Data Source=" + SQLServer + ""; conn.Open(); } catch(SqlException ex) { throw new Exception(ex.Message + ")(" + ex.Server + ")"); } catch (Exception) { throw; } }
public System.Data.DataTable GetDataTableRead(string SQLServer, string SQLTable, string SQLStatement) { using (SqlConnection conn = GetConnectionString(SQLServer,SQLTable)) { try { SqlCommand comm = new SqlCommand(); comm.Connection = conn; comm.CommandText = SQLStatement; comm.CommandType = CommandType.Text;
SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(reader); reader.Close();
reader.Dispose();
return dt; } catch (Exception) { throw; } } } } |
Ich hoffe mir kann einer sagen was ich falsch gemacht habt.
mfg
Seby
Moderiert von
Christian S.: Topic aus Sonstiges (C# / .NET) verschoben am Mi 17.10.2007 um 14:40