|
Hey there.
I just installed SQL Server express 2005 yesterday and I'm trying to connect to it using C# on Win 2000 SP4. I've never used SQL server so this is probably a novice question.
I used the following connection string to connect
SqlConnection conn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI; Initial Catalog=pubs");
However, I get the following error:
Exception Occured -->> System.Data.SqlClient.SqlException: An error has occurred
while establishing a connection to the server. When connecting to SQL Server 2
005, this failure may be caused by the fact that under the default settings SQL
Server does not allow remote connections. (provider: Named Pipes Provider, error
: 40 - Could not open a connection to SQL Server)
I am running the SQL Server service. I see the sqlservr.exe in the taskbar but I'm not sure if it is actually running.
Anyone know how I can connect to the sql server from C#?
Thank you!
-K
|
|
|
|
|
On SQL Server Express, the name of the datasource is like "SERVERNAME\SQLEXPRESS" where SERVERNAME is replaced by the name of your server. Rather than localhost, may be you can try the above syntax and check if it works.
In faith there is enough light for those who want to believe and enough shadows to blind those who don't.
- Blaise Pascal
|
|
|
|
|
Indeed! Thanks for your help god_bless.
Here is my final connection string:
SqlConnection conn = new SqlConnection(@"Server=.\SQLEXPRESS; Connect Timeout=5; Database=myTestDb; User ID=****; Password=****");
Also, since I am not using Windows authentication, I had add a user which I accomplished by
SQLCMD.exe -S (local)\SQLExpress -E
> EXEC sp_adduser '[machineName]\[userName]', '[userNameInDB]'
> GO
> EXEC sp_ addsrvrolemember '[userName]', 'sysadmin'
> GO
These steps are from this (excellent) tutorial: http://www.aspfree.com/c/a/MS-SQL-Server/Configuring-SQL-Server-Express-2005/
Finally, I made sure that the server was listening for the user I specified instead of some other user; that got rid of my Login Failed attempts.
Then, it finally worked!
-K
|
|
|
|
|
Hi;
I have this big problem in .net 2005 (C#). In the previouse version (2003) when we made a stored procedure we could simply drag and drop it into the screen and VIOLA you had all the code you needed for the procedure and with a little touch everything was fine. Now in .net 2005 I can't do that anymore or at least I dont know anyway. Could some one help me on this please or at least present another solution or 3rd party tool I could use.
I realy need to use SP.
Thanks very much
Hadi
|
|
|
|
|
Is likely a computer science education from a decent university. The teach concepts such as programming, ethics, and even into (which includes websearch). A good rule of thumb is: "If you can't code it by hand don't use the tool";
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
We have Microsoft SQL Server 2000. The database inside has very minimal information in it yet it uses 4 gigs of space. Why is it so big and how can we reduce its size?
|
|
|
|
|
Shrinking a Database [^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Turns out the log file has become very large. How can I purge this file? Can it be done from the enterprise manager?
|
|
|
|
|
I think this Mike Dimmick answers your questions:clickety[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Hello,
Im trying to create a SQL string that will insert values (Values that were gathered from a ASP.NET web form) into a table. The values are C# variables. I can insert manually typed values 'string' but when I try to make it a variable , I get an error. ORA-00984: column not allowed here. I either need the correct syntax for the sql string (values) or need to know the correct method for inserting C# variables into an oracle database.
Using MSVisual Studio 2005, ASP.NET webform, C#, Oracle 9i DB.
Sample of the code Im using...
protected void SubmitBtn_Click(object sender, EventArgs e)
{
String TodayStamp = DateTime.Today.ToString();
String EnteredFirstName = FirstNameTxtBox.Text;
String EnteredLastName = LastNameTxtBox.Text;
String EnteredCompany = CompanyNameTxtBox.Text;
String EnteredEmail = EmailAddTxtBox.Text;
String EnteredCity = CityTxtBox.Text;
String EnteredState = StateDropDownList.SelectedValue;
String EnteredCountry = CountryDropDownList.SelectedValue;
string strSQL = "INSERT INTO table(Firstname, Lastname, Company, Email, City, State, ActivityDate, Country) VALUES (EnteredFirstName, EnteredLastName, EnteredCompany, EnteredEmail, EnteredCity, EnteredState, TodayStamp, EnteredCountry )" ;
OdbcConnection conn = new OdbcConnection(ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString);
OdbcCommand myODBCCommand = new OdbcCommand( strSQL, conn);
try
{
conn.Open();
myODBCCommand.ExecuteNonQuery(); **Errors Here**
}
catch
{
}
finally
{
conn.Close();
}
}
Can anyone help please??
thanks...
David
|
|
|
|
|
string strSQL = "INSERT INTO table(Firstname, Lastname, Company, Email, City, State, ActivityDate, Country) VALUES ('"+ <br />
EnteredFirstName +"','"+<br />
EnteredLastName + "','" + <br />
EnteredCompany+ "','" + <br />
EnteredEmail+ "','" + <br />
EnteredCity+ "','" + <br />
EnteredState+ "','" + <br />
TodayStamp+ "','" +<br />
EnteredCountry +"')" ;
|
|
|
|
|
|
Thanks for yourm warning.
Sure I have read about it.
|
|
|
|
|
|
Oracle tutorials etc... where you can also find intimate details of error ORA-00984
[^]
modified 1-Aug-19 21:02pm.
|
|
|
|
|
Thanks both....
I will start with the first solution in development and then work on the attacks problem before I move to production.
David
|
|
|
|
|
In above code, strSQL does not translate variable value because it is included instring.
Please releace above string with following strSQl
string strSQL = "INSERT INTO table(Firstname, Lastname, Company, Email, City, State, ActivityDate, Country) VALUES('" + EnteredFirstName + "','" + EnteredLastName + "','" + EnteredCompany + "','" + EnteredEmail + "','" + EnteredCity + "','" + EnteredState + "','" + TodayStamp + "','" + EnteredCountry + "')";
myODBCCommand.ExecuteNonQuery() will also fetch error if your passing value doesnot match with database datatype
Kumar
|
|
|
|
|
Dear All
I have taken a backup for my database and trying to restore it on another computer .....but its showing me error while i m restoring this database...
error is Too many backup devices specified for backup or restore only 64 are allowed.
pls give me a solution if someone knows abt that...
Dinesh Sharma
|
|
|
|
|
|
my application is actually a web application where i manually upload CSV file to the database.but i want to automate the process,so i have thought of a second stage to this application i.e through a windows application i would download the CSV file from the NSEIndia.com site automatically and then upload the same to SQLServer on the server.i am facing a problem with upload i.e exporting the data to the database.it would be a great help to me if any one could provide me a solution either in VB.Net code or C# code.
AMIT(TATA CMC)
|
|
|
|
|
|
Hey everybody
Ok so here i am, programming a bit for 2 years now (VB.Net 2003). And now i got a lot of data, like 30000 items with many properties and stuff. From all those i want to select only a couple based on those properties and then do stuff with it. So i was thinking about a database. But were do start? I was reading some tutorial and they started with a connection string, but how do i know which connection i have? Do i have to install something?
Database stuff is a huge black hole in my head, so any help would be welcome
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
-- modified at 0:53 Tuesday 11th July, 2006
|
|
|
|
|
|
Some of these are good:
http://www.codeproject.com/vb/net/#Data+Access[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Hi,
Using VS2003 and C#, I have created oleDbAdapaters to fill a data set and used a combo box to allow easy selection of choices for amending record fields. Here's the code for the combobox:
// comboBoxMembershipLevel
//
this.comboBoxMembershipLevel.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.myClubDataSet12,"MembershipLevels.MembershipLevelName"));
this.comboBoxMembershipLevel.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.myClubDataSet12, "MemberDetails.MembershipLevel"));
this.comboBoxMembershipLevel.DataSource = this.myClubDataSet12.MembershipLevels;
this.comboBoxMembershipLevel.DisplayMember = "MembershipLevelName";
this.comboBoxMembershipLevel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.comboBoxMembershipLevel.Location = new System.Drawing.Point(584, 80);
this.comboBoxMembershipLevel.Name = "comboBoxMembershipLevel";
this.comboBoxMembershipLevel.Size = new System.Drawing.Size(121, 21);
this.comboBoxMembershipLevel.TabIndex = 40;
this.comboBoxMembershipLevel.ValueMember = "MembershipLevel";
//
The table "MembershipLevels" has three fields - ID(autogenerated key), MembershipLevel(int) and MembershipLevelName(text). The MemebershipLevel is stored for each record in the table MembersDetails.MembershipLevel(int).
When I select the first member of the drop down list and then move away and back to the record concerned I get 'System.Data.DataRowView' in the display box. Chosing any of the other members of the drop down list and all works fine - it only occurs when I chose the first member of the drop down list.
Saving the changes from the dataset to the database whilst the 'System.Data.DataRowView' is showing updates the database with the correct field data (ie a number and not 'System.Data.DataRowView').
Be kind to me - Im only learning.
TIA.
Regards,
Glen Harvy
|
|
|
|