Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Programatically Create a Stored Procedure...?
Message
From
19/05/2006 20:38:33
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
VB.NET 1.1
Miscellaneous
Thread ID:
01122634
Message ID:
01123712
Views:
15
>I kept getting the procedure in the master database. Knowing my luck I was doing something wrong...

The key concept here is to not do it all in one ExecuteNonQuery(), but to do it in several, but keeping the same connection.

>but it was a while ago and I tried so many things that I can't really remember.<

Happens to me ALL the time! I'd forget my head if it wasn't attached (I know, extremely old joke)!! But, I've got an excuse ... I'm getting too old for this sh*t! <g>

~~Bonnie




>If so then my apologies, but I could have sworn I tried something of that nature and it wasn't working for me. I kept getting the proceduer in the master database. Knowing my luck I was doing something wrong...but it was a while ago and I tried so many things that I can't really remember.
>
>>Actually, Ben, Fred is right ... maybe I should have replied to him yesterday to give him an "attaboy" when I saw his post. Here's how you would do this:
>>
>>string ConnString = "server=(local);uid=sa;pwd=";
>>
>>SqlConnection oConn = new SqlConnection(ConnString);
>>SqlCommand sc = new SqlCommand("use MyDataBase", oConn);
>>oConn.Open();
>>sc.ExecuteNonQuery();
>>
>>sc.CommandText = "select * from MyTable";
>>SqlDataAdapter da = new SqlDataAdapter(sc);
>>
>>DataSet ds = new DataSet();
>>da.Fill(ds);
>>oConn.Close();
>>
>>
>>The trick is to open the connection and "use" your database, then keeping the same connection, do whatever else you need to do.
>>
>>~~Bonnie
>>
>>
>>>>You don't need to connect to your database in your connection string, just to your server. You can then connect to the appropriate database using the "USE yourdatabase" command via a SQLEXEC. This way, you can change databases using the same connection.
>>>
>>>Actually, as it was stated by Borislav and Bonnie earlier in this thread...one has to use the database name in the connection string (Initial Catalog=...) otherwise it won't work. It you notice in my original posting, I mentioned that I tried using the "USE " SQL command and it came back with an error stating that CREATE PROCEDURE has to be the first executing statement in a batch.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform