- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- How to connect to Microsoft SQL Server Database
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
How to connect to Microsoft SQL Server Database
Hi Everyone,
In one of my project, I need to connect to database and then run a sql query to get the number of tables in the database, and I am trying to do this using installscript, but I am facing many issues, I tried it using ADO object, but there are some errors poping up, so does anybody know how to get this, please help me, i'm totally stuck in this
I have used this code:-
sConnString = "driver={SQL Server};";
sConnString = sConnString + "server=" +szServer+";";
sConnString = sConnString + "uid=" +szUsername+";";
sConnString = sConnString + "pwd=" +szPassword+";";
sConnString = sConnString + "database=" +szDb;
try
set AdoConnectionObj = CoCreateObject("ADODB.Connection");
AdoConnectionObj.ConnectionString = sConnString;
AdoConnectionObj.Open;
set AdoCommandObj = CreateObject("ADODB.Command");
AdoCommandObj.ActiveConnection = AdoConnectionObj;
AdoCommandObj.CommandText = szQuery;
AdoCommandObj.Execute();
catch
Is this right, please correct me if I'm wrong.
Also please let me know if there is anyother way to get this.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Here are some corrections to your SQL connection string:
sConnString = "Provider=sqloledb;";
sConnString = sConnString + "Data Source=" +szServer+";";
sConnString = sConnString + "User Id=" +szUsername+";";
sConnString = sConnString + "Password=" +szPassword+";";
sConnString = sConnString + "Initial Catalog=" +szDb;
reference: https://www.connectionstrings.com/microsoft-ole-db-provider-for-sql-server-sqloledb/
HTH
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
1. Are you certain the User Id and Password are correct?
2. Can you test the connection information using SQL Server Management Studio?